question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using async method and `ParseIntPipe` for generated resources controllers and services[restful] .

See original GitHub issue

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

For now, nest g mo cat [restful] will generated controllers like this:

  @Get(':id')
 findOne(@Param('id') id: string) {
    return this.catService.findOne(+id);
  }

There is two problems I think:

  1. use + to convert string to number
  2. the method is sync, but usually we will get resources from db which be async

Describe the solution you’d like

It would better to solve problem one using ParseIntPipe and make methods async.

  @Get(':id')
   async findOne(@Param('id', ParseIntPipe) id: number) {
    return await this.catService.findOne(id);
  }

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

as related to a problem part say.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
micaleviskcommented, Aug 31, 2022

got you

I’d leave those +id then

1reaction
notzhengcommented, Aug 28, 2022

would you like to open a PR to add those async on them?

sorry for late, I’d like to do~

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · nestjs/schematics - GitHub
When converting project to a monorepo configure all E2E tests to be run needs triage. #1167 opened ; Using async method and ParseIntPipe...
Read more >
Task asynchronous programming model - Microsoft Learn
Learn when and how to use Task-based async programming, a simplified approach to asynchronous programming in C#.
Read more >
Pipes | NestJS - A progressive Node.js framework
In our ParseIntPipe example, we want to associate the pipe with a particular route ... schema for a given controller method using the...
Read more >
Introduction to RESTful APIs with NestJS - This Dot Labs
The installation of NestJS comes with a sample API endpoint that we can test by making a request to it. If we open...
Read more >
Long Story Short: Async/Await Best Practices in .NET - Medium
NET programming — any C# developer worth his/her salt should be using it to improve application performance, overall responsiveness, and code ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found