From 500b0916fe93aeb510361570d8688eb28e13ad93 Mon Sep 17 00:00:00 2001 From: pushedrumex Date: Mon, 21 Nov 2022 15:22:09 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20#52=20=EC=95=84=EC=9D=B4=EB=94=94=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=EC=B2=B4=ED=81=AC=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/user/dto/check-user.dto.ts | 6 ++++++ server/src/user/user.controller.ts | 9 ++++++++- server/src/user/user.service.ts | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 server/src/user/dto/check-user.dto.ts diff --git a/server/src/user/dto/check-user.dto.ts b/server/src/user/dto/check-user.dto.ts new file mode 100644 index 0000000..7f55c28 --- /dev/null +++ b/server/src/user/dto/check-user.dto.ts @@ -0,0 +1,6 @@ +export class CheckUserDto { + private userId: string; + getUserId() { + return this.userId; + } +} diff --git a/server/src/user/user.controller.ts b/server/src/user/user.controller.ts index e028229..324746e 100644 --- a/server/src/user/user.controller.ts +++ b/server/src/user/user.controller.ts @@ -1,7 +1,8 @@ -import { Body, Controller, Get, Post } from "@nestjs/common"; +import { Body, Controller, Get, Param, Post } from "@nestjs/common"; import { CreateUserDto } from "./dto/create-user.dto"; import { UserService } from "./user.service"; import { plainToClass } from "class-transformer"; +import { CheckUserDto } from "./dto/check-user.dto"; @Controller("user") export class UserController { @@ -12,4 +13,10 @@ export class UserController { createUserDto = plainToClass(CreateUserDto, createUserDto); return this.userService.create(createUserDto); } + + @Get(":userId") + async checkId(@Param() checkUserDto: CheckUserDto) { + checkUserDto = plainToClass(CheckUserDto, checkUserDto); + return this.userService.checkId(checkUserDto); + } } diff --git a/server/src/user/user.service.ts b/server/src/user/user.service.ts index 0aacccc..ae41063 100644 --- a/server/src/user/user.service.ts +++ b/server/src/user/user.service.ts @@ -2,6 +2,7 @@ import { BadRequestException, Injectable } from "@nestjs/common"; import * as bcrypt from "bcryptjs"; import { UserRepository } from "./user.repository"; import { CreateUserDto } from "./dto/create-user.dto"; +import { CheckUserDto } from "./dto/check-user.dto"; @Injectable() export class UserService { @@ -18,4 +19,17 @@ export class UserService { await this.userRepository.save(userEntity); return { status: 201 }; } + + async checkId(checkUserDto: CheckUserDto) { + if (await this.userRepository.findByUserId(checkUserDto.getUserId())) { + return { + status: "200", + exists: true, + }; + } + return { + status: "200", + exists: false, + }; + } }