Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

254
Views
Anular la respuesta de nestjs/crud

Utilizo para este proyecto nest y la biblioteca nestjs/crud. Desafortunadamente, no puedo anular la función createOneBase para que devuelva una respuesta de persona. Busqué una solución en las últimas publicaciones del mismo tema. Me gustaría cambiar la respuesta cuando creo un usuario.

lo que tengo:

 { "id": 12, "username": "test", "password": "tests", "email": "test@foo.bar" }

lo que espero:

 { "id": 12, "username": "test", "password": "tests", "email": "test@foo.bar", "token": "TOKEN" }

mi controlador:

 import { Controller } from '@nestjs/common'; import { UsersService } from './users.service'; import { Crud, Override, ParsedRequest, ParsedBody, CrudRequest, CrudController } from '@nestjsx/crud'; import { User, UserDTO } from './user'; @Crud({ model: { type: User, }, }) @Controller('users') export class UsersController { constructor(public service: UsersService) {} get base(): CrudController<User | UserDTO> { return this; } @Override() createOne( @ParsedRequest() req: CrudRequest, @ParsedBody() dto: User, ): Promise<User | UserDTO> { const userDto: UserDTO = { id: dto.id, username: dto.username, password: dto.password, email: dto.email, token: 'TOKEN', }; return this.base.createOneBase(req, userDto); } }

mis entidades:

 import { IsDefined, IsString, MinLength } from 'class-validator'; import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm'; @Entity() export class User { @PrimaryGeneratedColumn() id: number; @Column() @IsDefined({ always: true }) @IsString({ always: true }) @MinLength(1, { always: true }) username: string; @Column() @IsDefined({ always: true }) @IsString({ always: true }) @MinLength(5, { always: true }) password: string; @Column() @IsDefined({ always: true }) @IsString({ always: true }) @MinLength(1, { always: true }) email: string; } export class UserDTO { id: number; username: string; password: string; email: string; token: string; access_token?: string; }

asi que no entiendo que le pasa, gracias por tu ayuda

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Para anular un método Nestjs/Crud, use el decorador @Override(functionName) Nestjs/Crud Doc

 @Override('createOneBase') createOne( @ParsedRequest() req: CrudRequest, @ParsedBody() dto: Hero) { return this.base.createOneBase(req, dto); }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!