Skip to content

Commit

Permalink
feat: 회원탈퇴 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondanythings committed Dec 31, 2023
1 parent 4782dc1 commit 80626d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/users/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
import { Body, Controller, Delete, Get, Post, UseGuards } from '@nestjs/common';
import { UserService } from './user.service';
import { AccessGuard } from 'src/auth/guards/acess.guard';
import { AuthUser } from 'src/auth/decorators/auth-user.decorator';
Expand Down Expand Up @@ -37,6 +37,17 @@ export class UserController {
return await this.userService.getMe(id);
}

@ApiOperation({
summary: '회원탈퇴',
description: '나의 계정정보를 삭제한다.',
})
@ApiOkResponse()
@UseGuards(AccessGuard)
@Delete()
async deleteMe(@AuthUser() { id }: Payload) {
return await this.userService.getMe(id);
}

@ApiOperation({
summary: '닉네임 변경',
description: '나의 닉네임을 설정/변경한다.',
Expand Down
19 changes: 18 additions & 1 deletion src/users/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UserRepository } from './user.repository';
import { UserResponse } from './dtos/user.dto';
import { Injectable } from '@nestjs/common';
import { BadRequestException, Injectable } from '@nestjs/common';
import { InjectDataSource } from '@nestjs/typeorm';
import { User } from 'src/users/entities/user.entity';
import { DataSource } from 'typeorm';
Expand Down Expand Up @@ -106,4 +106,21 @@ export class UserService {
return false;
}
}

async deleteMe(userId: string) {
try {
const exist = await this.userCatRepository.findOneOrFail({
where: {
id: userId,
},
});
if (exist) {
await this.userRepository.softDelete({ id: userId });
return true;
}
return false;
} catch (error) {
throw new BadRequestException();
}
}
}

0 comments on commit 80626d4

Please sign in to comment.