-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from serafuku/yunochi/develop
✨ 계정 삭제기능 추가 + 버그수정
- Loading branch information
Showing
11 changed files
with
185 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { IsString } from "class-validator"; | ||
|
||
export class AccountDeleteReqDto { | ||
@IsString() | ||
handle: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { AccountDeleteReqDto } from '@/app/_dto/account-delete/account-delete.dto'; | ||
import { RateLimit } from '@/app/api/_service/ratelimiter/decorator'; | ||
import { sendApiError } from '@/app/api/_utils/apiErrorResponse/sendApiError'; | ||
import { GetPrismaClient } from '@/app/api/_utils/getPrismaClient/get-prisma-client'; | ||
import { Auth, JwtPayload } from '@/app/api/_utils/jwt/decorator'; | ||
import { jwtPayloadType } from '@/app/api/_utils/jwt/jwtPayloadType'; | ||
import { Body, ValidateBody } from '@/app/api/_utils/Validator/decorator'; | ||
import { Logger } from '@/utils/logger/Logger'; | ||
import { PrismaClient } from '@prisma/client'; | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
export class AccountDeleteService { | ||
private logger: Logger; | ||
private prisma: PrismaClient; | ||
private static instance: AccountDeleteService; | ||
private constructor() { | ||
this.logger = new Logger('AccountDeleteService'); | ||
this.prisma = GetPrismaClient.getClient(); | ||
} | ||
public static getInstance() { | ||
if (!AccountDeleteService.instance) { | ||
AccountDeleteService.instance = new AccountDeleteService(); | ||
} | ||
return AccountDeleteService.instance; | ||
} | ||
|
||
@ValidateBody(AccountDeleteReqDto) | ||
@Auth() | ||
@RateLimit({ bucket_time: 60, req_limit: 60 }, 'ip') | ||
public async deleteAccountApi( | ||
_req: NextRequest, | ||
@Body body: AccountDeleteReqDto, | ||
@JwtPayload tokenBody: jwtPayloadType, | ||
): Promise<NextResponse> { | ||
if (body.handle !== tokenBody.handle) { | ||
return sendApiError(401, 'Handle not match with JWT handle', 'UNAUTHORIZED'); | ||
} | ||
const user = await this.prisma.user.findUniqueOrThrow({ where: { handle: tokenBody.handle } }); | ||
this.logger.log(`Delete user ${user.handle}`); | ||
await this.prisma.question.deleteMany({ where: { questioneeHandle: user.handle } }); | ||
await this.prisma.answer.deleteMany({ where: { answeredPersonHandle: user.handle } }); | ||
await this.prisma.following.deleteMany({ where: { followerHandle: user.handle } }); | ||
await this.prisma.blocking.deleteMany({ where: { blockerHandle: user.handle } }); | ||
await this.prisma.notification.deleteMany({ where: { userHandle: user.handle } }); | ||
await this.prisma.profile.delete({ where: { handle: user.handle } }); | ||
await this.prisma.user.delete({ where: { handle: user.handle } }); | ||
this.logger.log(`User ${user.handle} deleted!`); | ||
return NextResponse.json({ message: 'Good bye' }, { status: 200 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { AccountDeleteService } from "@/app/api/_service/account/account-delete.service"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export async function POST(req: NextRequest): Promise<NextResponse> { | ||
const deleteService = AccountDeleteService.getInstance(); | ||
return await deleteService.deleteAccountApi(req, null as any, null as any); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default function AnswerNotFoundPage() { | ||
return ( | ||
<div className="w-[90%] window:w-[80%] desktop:w-[70%] grid grid-cols-1 desktop:grid-cols-2 gap-4"> | ||
<div className="w-full col-span-2 flex flex-col justify-center items-center glass text-4xl rounded-box shadow p-2"> | ||
😶🌫️ | ||
<span> 답변을 찾을 수 없어요! </span> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default function UserNotFoundPage() { | ||
return ( | ||
<div className="w-[90%] window:w-[80%] desktop:w-[70%] grid grid-cols-1 desktop:grid-cols-2 gap-4"> | ||
<div className="w-full col-span-2 flex flex-col justify-center items-center glass text-4xl rounded-box shadow p-2"> | ||
😶🌫️ | ||
<span>그런 사용자는 없어요!</span> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters