diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index b8be40a..c243467 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -1,8 +1,4 @@ -import { - Injectable, - NotFoundException, - UnauthorizedException, -} from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { JwtService } from '@nestjs/jwt'; import { Response } from 'express'; @@ -13,6 +9,7 @@ import { ResponseBody, SuccessResponse } from '../common/response/response'; import { RESPONSE_CODE } from '../common/response/response.code'; import { JoinDto } from './dtos/request/join.dto'; import { LoginDto } from './dtos/request/login.dto'; +import { Exception } from '../common/response/exception'; @Injectable() export class AuthService { @@ -28,7 +25,7 @@ export class AuthService { where: [{ id: joinDto.id }, { nickname: joinDto.nickname }], }) ) { - throw new UnauthorizedException('user already exists.'); + throw new Exception(RESPONSE_CODE[4090], null); } const userInDto: User = this.usersRepository.create(joinDto); @@ -38,11 +35,13 @@ export class AuthService { async login(loginDto: LoginDto, response: Response): Promise { const userData = await this.usersRepository.findOne({ - where: [{ id: loginDto.id }, { password: loginDto.password }], - select: { id: true, password: true, nickname: true }, + where: { + id: loginDto.id, + password: loginDto.password, + }, }); if (!userData) { - throw new NotFoundException('user not found.'); + throw new Exception(RESPONSE_CODE[4040], null); } const payload: Payload = { diff --git a/src/common/response/response.code.ts b/src/common/response/response.code.ts index 3e5a265..e5c19a8 100644 --- a/src/common/response/response.code.ts +++ b/src/common/response/response.code.ts @@ -22,4 +22,14 @@ export const RESPONSE_CODE: Record = { message: '서버 에러', status: HttpStatus.INTERNAL_SERVER_ERROR, }, + 4040: { + code: 4040, + message: '유저 정보가 존재하지 않습니다.', + status: HttpStatus.NOT_FOUND, + }, + 4090: { + code: 4090, + message: '이미 존재하는 유저입니다.', + status: HttpStatus.CONFLICT, + }, };