Skip to content

Commit

Permalink
Merge pull request #54 from boostcampwm-2022/feat/idCheck
Browse files Browse the repository at this point in the history
feat: #52 ์•„์ด๋”” ์ค‘๋ณต์ฒดํฌ API
  • Loading branch information
pushedrumex authored Nov 21, 2022
2 parents 28d37c9 + 1ef3f6a commit 36b2e38
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions server/src/user/dto/check-user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class CheckUserDto {
private userId: string;
getUserId() {
return this.userId;
}
}
9 changes: 8 additions & 1 deletion server/src/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -11,4 +12,10 @@ export class UserController {
async create(@Body() createUserDto: CreateUserDto) {
return this.userService.create(createUserDto);
}

@Get(":userId")
async checkId(@Param() checkUserDto: CheckUserDto) {
checkUserDto = plainToClass(CheckUserDto, checkUserDto);
return this.userService.checkId(checkUserDto);
}
}
14 changes: 14 additions & 0 deletions server/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
};
}
}

0 comments on commit 36b2e38

Please sign in to comment.