Skip to content

Commit

Permalink
Merge pull request #30 from 5th-Neordinary-HACKATHON-MEETA/issue/27
Browse files Browse the repository at this point in the history
Refactor: response code 리팩터링, 중복검사 추가 - #27
  • Loading branch information
cookie-meringue authored Nov 25, 2023
2 parents 297775e + ebcf1c3 commit 0fbafb0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Body, Controller, HttpCode, Post, Res } from '@nestjs/common';
import {
Body,
Controller,
Get,
HttpCode,
Post,
Query,
Res,
} from '@nestjs/common';
import { AuthService } from './auth.service';
import { Response } from 'express';
import { JoinDto } from './dtos/request/join.dto';
Expand All @@ -23,6 +31,11 @@ export class AuthController {
return await this.authService.login(loginDto, response);
}

@Get('duplicate')
async duplicate(@Query('compareId') id: string): Promise<ResponseBody> {
return await this.authService.duplicate(id);
}

//@Post('test')
//@UseGuards(JwtAuthGuard) //이걸 통해서 jwt를 검증하고 req.user에 user를 넣어준다.
//hello(@AuthUser() user: User) {
Expand Down
18 changes: 15 additions & 3 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export class AuthService {
async join(joinDto: JoinDto): Promise<ResponseBody> {
if (
await this.usersRepository.findOne({
where: [{ id: joinDto.id }, { nickname: joinDto.nickname }],
where: { id: joinDto.id },
})
) {
throw new Exception(RESPONSE_CODE[4090], null);
throw new Exception(RESPONSE_CODE[14090], null);
}

const userInDto: User = this.usersRepository.create(joinDto);
Expand All @@ -41,7 +41,7 @@ export class AuthService {
},
});
if (!userData) {
throw new Exception(RESPONSE_CODE[4040], null);
throw new Exception(RESPONSE_CODE[14040], null);
}

const payload: Payload = {
Expand All @@ -54,4 +54,16 @@ export class AuthService {
response.header('Authorization', 'Bearer ' + sign);
return SuccessResponse(RESPONSE_CODE[2000], { id: userData.id });
}

async duplicate(id: string): Promise<ResponseBody> {
let isDuplicate = false;
if (
await this.usersRepository.findOne({
where: { id: id },
})
) {
isDuplicate = true;
}
return SuccessResponse(RESPONSE_CODE[2000], { isDuplicate: isDuplicate });
}
}
6 changes: 6 additions & 0 deletions src/auth/dtos/request/duplicate.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IsString } from 'class-validator';

export class DuplicateDto {
@IsString()
id!: string;
}

0 comments on commit 0fbafb0

Please sign in to comment.