Skip to content

Commit

Permalink
refactor(#10): 계정 삭제 명세서 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoDora committed Oct 12, 2023
1 parent eebd9e6 commit 11d32ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
5 changes: 5 additions & 0 deletions src/auth/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ export class AuthController {
return await this.authService.naverUnlink(naverAccessToken);
}

@ApiOperation({ summary: '계정 삭제 API', description: '계정 삭제 API' })
@ApiResponse({ status: 200, description: '성공적으로 계정이 삭제 된 경우', content: { JSON: { example: { message: "사용자 계정 삭제에 성공했습니다." } } } })
@ApiResponse({ status: 403, description: '만료된 액세스 토큰인 경우', content: { JSON: { example: { statusCode: 403, message: '만료된 토큰입니다.' } } } })
@ApiResponse({ status: 404, description: 'DB에서 사용자를 찾을 수 없는 경우', content: { JSON: { example: { statusCode: 404, message: '사용자를 찾을 수 없습니다.' } } } })
@ApiHeaders([{ name: 'access_token', description: '액세스 토큰', required: true, example: '여기에 액세스 토큰' }])
@Delete('account')
async accountDelete(@Headers('access_token') accessToken: string) {
const userId = await this.tokenService.decodeToken(accessToken);
Expand Down
4 changes: 2 additions & 2 deletions src/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ export class AuthService {
async accountDelete(userId: number) {
const deleteUser = await this.userRepository.deleteUser(userId);
if (!deleteUser) {
return "사용자 계정 삭제에 실패했습니다.";
throw new HttpException('사용자를 찾을 수 없습니다.', HttpStatus.NOT_FOUND);
}
return "사용자 계정 삭제에 성공했습니다.";
return { message: "사용자 계정 삭제가 완료되었습니다." };
}
}
18 changes: 4 additions & 14 deletions src/users/repositories/user.repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { EntityManager } from 'typeorm';
import { DeleteResult, EntityManager } from 'typeorm';
import { User } from '../entities/user.entity';

@Injectable()
Expand Down Expand Up @@ -34,18 +34,8 @@ export class UserRepository {
return this.entityManager.save(user);
}

async deleteUser(userId: number): Promise<User | null> {
try {
const user = await this.entityManager.findOne(User, { where: { id: userId } });
if (!user) {
throw new NotFoundException('사용자를 찾을 수 없습니다.');
} else {
await this.entityManager.delete(User, { id: userId });
return user;
}
} catch (error) {
console.error('사용자 삭제 오류:', error);
return null;
}
async deleteUser(userId: number): Promise<DeleteResult | undefined> {
await this.entityManager.findOne(User, { where: { id: userId } });
return await this.entityManager.delete(User, { id: userId });
}
}

0 comments on commit 11d32ff

Please sign in to comment.