fix: dto returns
This commit is contained in:
26
backend/src/user/dto/user.dto.ts
Normal file
26
backend/src/user/dto/user.dto.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Expose, plainToClass } from "class-transformer";
|
||||
import { IsEmail, IsNotEmpty, IsString } from "class-validator";
|
||||
|
||||
export class UserDTO {
|
||||
@Expose()
|
||||
id: string;
|
||||
|
||||
@Expose()
|
||||
firstName: string;
|
||||
|
||||
@Expose()
|
||||
lastName: string;
|
||||
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsEmail()
|
||||
email: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
password: string;
|
||||
|
||||
from(partial: Partial<UserDTO>) {
|
||||
return plainToClass(UserDTO, partial, { excludeExtraneousValues: true });
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,13 @@ import { Controller, Get, UseGuards } from "@nestjs/common";
|
||||
import { User } from "@prisma/client";
|
||||
import { GetUser } from "src/auth/decorator/getUser.decorator";
|
||||
import { JwtGuard } from "src/auth/guard/jwt.guard";
|
||||
import { UserDTO } from "./dto/user.dto";
|
||||
|
||||
@Controller("users")
|
||||
export class UserController {
|
||||
@Get("me")
|
||||
@UseGuards(JwtGuard)
|
||||
async getCurrentUser(@GetUser() user: User) {
|
||||
return user;
|
||||
return new UserDTO().from(user);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user