ripstop
20
2022-04-05 16:29:46
0
169

nestJs 유저 생성 질문


안녕하세요 createUserDto를 통해서 DB(postgreSQL)에 테이블을 전달하려고 했으나 


하단과 같은 에러가 나옵니다.


하단은 에러 원인과 관련된 제 코드입니다.


users.controller.ts


@Controller('users')

export class UsersController {

    constructor (private readonly usersService:UsersService){}

    ...

    @Post()

    @UsePipes(ValidationPipe)

    async createBoard(@Body() createUserDto: CreateUserDto){//CreateUserDto

      console.log(createUserDto) //{} emptyObject

         const result=await this.usersService.createBoard(createUserDto);

         return result;

    }

createUser.dto.ts


import { PartialType } from "@nestjs/mapped-types";

import { MutationOutput } from "src/common/dtos/output.dto";

import { UserEntity } from "../entities/users.entity";



export class CreateUserDto extends PartialType(UserEntity){}



export class CreateAccountOutput extends MutationOutput{}


users.entity.ts



import { InternalServerErrorException } from "@nestjs/common";

import { IsEmail, IsEnum } from "class-validator";

import * as bcrypt from "bcrypt";

import { BeforeInsert, Column, Entity } from "typeorm";

import { CoreEntity } from "src/common/entities/core.entity";





export enum UserStatus {

    PUBLIC = 'PUBLIC',

    PRIVATE = 'PRIVATE'

}

@Entity()

export class UserEntity extends CoreEntity {



    @Column()

    @IsEmail()

    email:string;



    @Column()

    password: string;



    // @Column()

    // @IsOptional()

    // description?: string;



    @Column({type:"enum", enum:UserStatus})

    @IsEnum(UserStatus)

    status: UserStatus;



    // @BeforeInsert() //DB저장전에

    // async hashPassword(): Promise<void>{

    //     try{

    //         this.password = await bcrypt.hash(this.password,10); //PASSWORD를 받아서 hash

    //     }catch(e){

    //         console.log(e);

    //         throw new InternalServerErrorException()

    //     }

    // }



    // async checkPassword(aPassword:string): Promise<boolean>{

    //     try{

    //         const ok = await bcrypt.compare(aPassword, this.password)

    //         return ok;

    //     }

    //     catch(e){

    //         console.log(e)

    //         throw new InternalServerErrorException();

    //     }

    // }

}



0
  • 답변 0

  • 로그인을 하시면 답변을 등록할 수 있습니다.