forked from yy0ung/nibobnebob
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 핸들러 레벨 파이프 적용 - dto에 decorator를 통해 validation 규칙 적용 Co-authored-by: GeunH <[email protected]>
- Loading branch information
Showing
5 changed files
with
63 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,38 @@ | ||
import { | ||
IsBoolean, | ||
IsString, | ||
IsNotEmpty, | ||
IsEmail, | ||
IsInt, | ||
MaxLength, | ||
} from "class-validator"; | ||
|
||
export class UserInfoDto { | ||
email : string; | ||
password : string; | ||
provider : string; | ||
nickName: string; | ||
age: number; | ||
gender: string; | ||
} | ||
@IsEmail() | ||
@IsNotEmpty() | ||
@MaxLength(50) | ||
email: string; | ||
|
||
@IsString() | ||
@IsNotEmpty() | ||
@MaxLength(50) | ||
password: string; | ||
|
||
@IsString() | ||
@IsNotEmpty() | ||
@MaxLength(20) | ||
provider: string; | ||
|
||
@IsString() | ||
@IsNotEmpty() | ||
@MaxLength(20) | ||
nickName: string; | ||
|
||
@IsInt() | ||
@IsNotEmpty() | ||
age: number; | ||
|
||
@IsBoolean() | ||
@IsNotEmpty() | ||
gender: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
import { Controller, Get, Post, Body, UsePipes } from "@nestjs/common"; | ||
import { | ||
Body, | ||
Controller, | ||
Get, | ||
Post, | ||
UsePipes, | ||
ValidationPipe, | ||
} from "@nestjs/common"; | ||
import { UserInfoDto } from "./dto/userInfo.dto"; | ||
import { UserService } from "./user.service"; | ||
import { validateHeaderName } from "http"; | ||
|
||
@Controller("user") | ||
export class UserController { | ||
constructor(private userService:UserService) {} | ||
constructor(private userService: UserService) {} | ||
|
||
@Post() | ||
singup(@Body() userInfoDto : UserInfoDto) { | ||
@UsePipes(new ValidationPipe()) | ||
singup(@Body() userInfoDto: UserInfoDto) { | ||
try { | ||
const result = this.userService.signup(userInfoDto); | ||
return { message: 'User created successfully', data: result }; | ||
return { message: "User created successfully", data: result }; | ||
} catch (error) { | ||
return { message: 'User creation failed', error: error.message }; | ||
return { message: "User creation failed", error: error.message }; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { UserInfoDto } from './dto/userInfo.dto'; | ||
import { Injectable } from "@nestjs/common"; | ||
import { UserInfoDto } from "./dto/userInfo.dto"; | ||
@Injectable() | ||
export class UserService { | ||
signup( userInfoDto : UserInfoDto){ | ||
const { email, password, provider, nickName, age, gender } = userInfoDto; | ||
signup(userInfoDto: UserInfoDto) { | ||
const { email, password, provider, nickName, age, gender } = userInfoDto; | ||
|
||
// DB에 저장 | ||
|
||
return userInfoDto; | ||
|
||
} | ||
// DB에 저장 | ||
|
||
return userInfoDto; | ||
} | ||
} |