From 80626d4ca8c7e30f28a112ee9ba41de659473075 Mon Sep 17 00:00:00 2001 From: Raymond Date: Sun, 31 Dec 2023 20:46:11 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=ED=83=88=ED=87=B4=20?= =?UTF-8?q?API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/users/user.controller.ts | 13 ++++++++++++- src/users/user.service.ts | 19 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/users/user.controller.ts b/src/users/user.controller.ts index 6b72271..38a85d9 100644 --- a/src/users/user.controller.ts +++ b/src/users/user.controller.ts @@ -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'; @@ -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: '나의 닉네임을 설정/변경한다.', diff --git a/src/users/user.service.ts b/src/users/user.service.ts index 3b8f288..7a120c2 100644 --- a/src/users/user.service.ts +++ b/src/users/user.service.ts @@ -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'; @@ -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(); + } + } }