In Nest js I need to write an endpoint which makes a new "rent", is this a valid code?

For a school project I need to make a backend app. I use mysql database with two tables, one for products and one for rent information. @Post(‘:id/rent’) async rent(@Param(‘id’) id: number){ const carRepo= this.dataSource.getRepository(Car); const rentalRepo = this.dataSource.getRepository(Rental); const rental= new Rental; rental.start_date= new Date(); rental.end_date=new Date(); rental.end_date.setDate(rental.start_date.getDate() + 7) const car = await carRepo.findOneBy({id});… Read More In Nest js I need to write an endpoint which makes a new "rent", is this a valid code?

Problems to install NestJS

I want to install NestJS with the npm i -g @nestjs/cli command. npm ERR! code ENOTEMPTY npm ERR! syscall rename npm ERR! path /usr/local/lib/node_modules/@nestjs/cli npm ERR! dest /usr/local/lib/node_modules/@nestjs/.cli-seuz8ewr npm ERR! errno -39 npm ERR! ENOTEMPTY: directory not empty, rename ‘/usr/local/lib/node_modules/@nestjs/cli’ -> ‘/usr/local/lib/node_modules/@nestjs/.cli-seuz8ewr’ npm ERR! A complete log of this run can be found in: npm… Read More Problems to install NestJS

Why is my Nestjs Service being instantiated twice?

I have the following NgrokService here: @Injectable() export class NgrokService implements OnApplicationBootstrap, OnApplicationShutdown { port: string ngrokToken: string ngrok: typeof import(‘ngrok’) | null = null constructor(private readonly configService: ConfigService) { this.port = this.configService.get(‘API_PORT’) ?? ‘3001’ this.ngrokToken = this.configService.getOrThrow(‘NGROK_TOKEN’) if (process.env.NODE_ENV === ‘development’) this.ngrok = require(‘ngrok’) } async onApplicationBootstrap() { if (process.env.NODE_ENV !== ‘development’) { return… Read More Why is my Nestjs Service being instantiated twice?

Why is my Nestjs Service being instantiated twice?

I have the following NgrokService here: @Injectable() export class NgrokService implements OnApplicationBootstrap, OnApplicationShutdown { port: string ngrokToken: string ngrok: typeof import(‘ngrok’) | null = null constructor(private readonly configService: ConfigService) { this.port = this.configService.get(‘API_PORT’) ?? ‘3001’ this.ngrokToken = this.configService.getOrThrow(‘NGROK_TOKEN’) if (process.env.NODE_ENV === ‘development’) this.ngrok = require(‘ngrok’) } async onApplicationBootstrap() { if (process.env.NODE_ENV !== ‘development’) { return… Read More Why is my Nestjs Service being instantiated twice?

NestJS Shared Modules

I am reading Modules in NestJS official documentation and I wanted to try shared modules. So, I have the following structure for my application: src ├── cats │ ├── cats.controller.ts | ├── cats.module.ts | └── cats.service.ts ├── users │ ├── users.controller.ts | ├── users.module.ts | └── users.service.ts ├── app.controller.ts ├── app.module.ts ├── app.service.ts └── main.ts… Read More NestJS Shared Modules

NestJS Is a good aproach using DTO classes in request object?

I’m learning NestJS and now I’m working in a simple authentication application, at this point I configured global pipes to validations and I’m using dto classes for example to validate @Body() fields. I don’t know if I can use DTO to validate @Request fields sent from login endpoint. import { Controller, Post, Request, UseGuards }… Read More NestJS Is a good aproach using DTO classes in request object?