Skip to content
Advertisement

Tag: nestjs

Guard not returning authenticated user

I have created a guard And i am using it on of my endpoints The point is it is faling because getRequest is not returning the authenticated user it is returning undefined How can i return the authenticated user from the response ? Answer You should use your JwtAuthGuard at your controller level since nest doesn’t have an order to

How to deal with NestJS @Get() decorator?

This block of code works properly. I’m able to access both functions with the URL http://localhost:3000/vehicle/availableVehicles & http://localhost:3000/vehicle/1 accordingly But when I just swap between the 2 functions like code block below then the function availableVehicles() doesn’t work & the URL http://localhost:3000/vehicle/availableVehicles hits the getbyId() function. What to do? Or what I’m doing wrong? Thanks in advance. Answer You just

How to rate limit a NestJS API by multiple time intervals?

I am trying to rate limit my API with @NestJs/throttler. I want to set two different limit caps: 100 requests per 1 second 10,000 requests per 24 hours. Setting either one of these rate limits is explained in the docs and is pretty straight forwad. But, setting both limitations is not articulated in the docs. How can I rate limit

Is there a way to use static method with dependency injection in NestJS?

An example is better than a long explanation: How can I replace BakeryService.myStaticMethodToGetPrice() to use dependency injection, so I can test things easily for example? Answer Static methods cannot use dependency injection. This is because the idea of dependency injection (at least to Nest) is to inject instances of the dependencies so that they can be leveraged later. The code

How to print Firestore timestamp as formatted date and time like December 28,2020 at 3:52:04 AM UTC+5:30?

while fetching date from firestore I am getting Timestamp “seconds: 1608490949, nanoseconds: 275000000”.I want to print it as properly formatted date and time. As it is “December 28,2020 at 3:52:04 AM UTC+5:30”. Below is my pic of code Answer You can call javascript date functions here because this converting into javascript date https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString Or for more control on formatting, you

Differentiate 2 routes of a controller (NestJS)

EDIT: When I move the @Get(‘/random’) above the 2 other routes, it’s working… Weird I’m doing a NestJS server that just get some routes of the Breaking Bad API and displays the JSON in the routes of the server, I want to create 3 routes : 1 that returns a JSON of all characters of the show (/characters/all) 1 that

Advertisement