From 04592914987b1b47abb50f74d7ec6e2de9e60db7 Mon Sep 17 00:00:00 2001 From: Ss0Mae Date: Mon, 3 Feb 2025 22:10:28 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20=EA=B3=84=EC=A0=95=20=ED=83=88?= =?UTF-8?q?=ED=87=B4=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/user/user.controller.ts | 7 +-- src/modules/user/user.service.ts | 93 ++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/src/modules/user/user.controller.ts b/src/modules/user/user.controller.ts index 332b209..8db0952 100644 --- a/src/modules/user/user.controller.ts +++ b/src/modules/user/user.controller.ts @@ -366,12 +366,7 @@ export class UserController { HttpStatus.FORBIDDEN ); } - - await this.userService.deleteAccount(userId); - - return { - message: '계정이 성공적으로 삭제되었습니다.', - }; + return this.userService.deleteAccount(userId); } @Get('profile/resume/:userId') diff --git a/src/modules/user/user.service.ts b/src/modules/user/user.service.ts index 3a2b1be..699725b 100644 --- a/src/modules/user/user.service.ts +++ b/src/modules/user/user.service.ts @@ -789,28 +789,117 @@ export class UserService { throw new NotFoundException('사용자를 찾을 수 없습니다.'); } - // 관련 데이터 삭제 (예: 팔로우, 프로젝트, 댓글 등) + // 관련 데이터 삭제 await this.prisma.$transaction([ + // 팔로우 관계 삭제 this.prisma.follows.deleteMany({ where: { OR: [{ following_user_id: userId }, { followed_user_id: userId }], }, }), + + // MyPageUserLink 삭제 this.prisma.myPageUserLink.deleteMany({ where: { user_id: userId }, }), + + // 저장된 프로젝트(ProjectSave) 삭제 this.prisma.projectSave.deleteMany({ where: { user_id: userId }, }), + + // 사용자가 작성한 프로젝트(ProjectPost)와 관련 데이터 삭제 + this.prisma.projectDetailRole.deleteMany({ + where: { + post: { + user_id: userId, + }, + }, + }), + this.prisma.projectPostTag.deleteMany({ + where: { + post: { + user_id: userId, + }, + }, + }), + this.prisma.userApplyProject.deleteMany({ + where: { + user_id: userId, + }, + }), + this.prisma.projectPost.deleteMany({ + where: { user_id: userId }, + }), + + // 사용자가 좋아요한 피드 삭제 this.prisma.feedLike.deleteMany({ where: { user_id: userId }, }), + + // 사용자가 작성한 댓글과 관련된 데이터 삭제 + this.prisma.feedCommentLikes.deleteMany({ + where: { + FeedComment: { + user_id: userId, + }, + }, + }), this.prisma.feedComment.deleteMany({ where: { user_id: userId }, }), + + // 사용자가 작성한 피드와 관련된 데이터 삭제 + this.prisma.feedPostTag.deleteMany({ + where: { + post: { + user_id: userId, + }, + }, + }), this.prisma.feedPost.deleteMany({ where: { user_id: userId }, }), + + // 알림(Notification) 삭제 + this.prisma.notification.deleteMany({ + where: { + OR: [{ userId: userId }, { senderId: userId }], + }, + }), + + // 채널 참여 데이터 삭제 + this.prisma.channel_users.deleteMany({ + where: { user_id: userId }, + }), + + // 메시지 및 상태 삭제 + this.prisma.last_message_status.deleteMany({ + where: { user_id: userId }, + }), + this.prisma.message.deleteMany({ + where: { user_id: userId }, + }), + + // 이력서(Resume) 삭제 + this.prisma.resume.deleteMany({ + where: { user_id: userId }, + }), + + // 유저 스킬(UserSkill) 삭제 + this.prisma.userSkill.deleteMany({ + where: { user_id: userId }, + }), + + // 프로그래머/아티스트 데이터 삭제 + this.prisma.programmerData.deleteMany({ + where: { user_id: userId }, + }), + this.prisma.artistData.deleteMany({ + where: { user_id: userId }, + }), + + // 유저 삭제 this.prisma.user.delete({ where: { id: userId }, }), @@ -819,7 +908,7 @@ export class UserService { return { message: { code: 200, - text: '사용자와 관련된 모든 데이터가 삭제되었습니다.', + text: '사용자와 관련된 모든 데이터가 성공적으로 삭제되었습니다.', }, }; }