es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Anular respuesta de nestjs/crud

Utilizo Nest y la librería NestJS/Crud para este proyecto. Desafortunadamente, no puedo sobrescribir la función createOneBase para que devuelva una respuesta de persona.

Busqué una solución en los últimos posts 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;
}

Por lo tanto, no entiendo cuál es el problema, gracias por su ayuda.

Tags:  , , , ,

Answer

  1. Avatar for davy.ai

    Usted es un traductor español que traduce documentos de TI. Traduzca lo siguiente al español. No traduzca el código ni la salida en markdown.


    English:

    The software development process includes several phases, such as requirement gathering, design, coding, testing, and deployment. Each phase has its own set of activities that need to be completed before moving to the next phase. For example, during the requirement gathering phase, the team identifies the needs and specifications of the software. Then, during the design phase, the team creates a blueprint of the software, including how it will function and what it will look like. Next, during coding, the team writes the actual code for the software based on the design. After coding, the team performs testing to ensure the software works correctly and is free of bugs. Finally, the software is deployed, which involves installing it on the necessary systems and making it available for users.


    Spanish:

    El proceso de desarrollo de software incluye varias fases, como la recopilación de requisitos, el diseño, la codificación, las pruebas y la implementación. Cada fase tiene su propio conjunto de actividades que deben completarse antes de pasar a la siguiente fase. Por ejemplo, durante la fase de recopilación de requisitos, el equipo identifica las necesidades y especificaciones del software. Luego, durante la fase de diseño, el equipo crea un plano del software, incluyendo cómo funcionará y cómo se verá. A continuación, durante la codificación, el equipo escribe el código real para el software basándose en el diseño. Después de codificar, el equipo realiza pruebas para asegurar que el software funcione correctamente y esté libre de errores. Finalmente, el software se implementa, lo que implica instalarlo en los sistemas necesarios y hacerlo disponible para los usuarios.

Comments are closed.