From 76fea71ffd4848f9d2330760f8b72a87ec34df52 Mon Sep 17 00:00:00 2001 From: leGit-y Date: Wed, 22 Nov 2023 15:44:12 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20review=EA=B0=80=20=EC=97=86=EB=8A=94?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20delete=20review,=20delete=20worry=20transa?= =?UTF-8?q?ction=EB=B6=88=EA=B0=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/repository/worryRepository.ts | 20 +++++++++++--------- src/service/worryService.ts | 11 ++++++----- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/repository/worryRepository.ts b/src/repository/worryRepository.ts index 93de1f4..35b89be 100644 --- a/src/repository/worryRepository.ts +++ b/src/repository/worryRepository.ts @@ -66,7 +66,7 @@ const updateWorry = async(worryUpdateDTO: worryUpdateDTO) => { }) } -const deleteWorry = async(worryId:number) => { +const deleteWorryWithReview = async(worryId:number) => { const deleteReview = prisma.review.delete({ where:{ @@ -84,15 +84,16 @@ const deleteWorry = async(worryId:number) => { } -// const deleteWorryByUserId = async(userId:number) => { +const deleteWorryWithoutReview = async(worryId:number) => { -// return await prisma.worry.deleteMany({ -// where: { -// user_id: userId -// } -// }) + return await prisma.worry.delete({ + where: { + id: worryId + } + }) + +} -// } const findWorryById = async(worryId:number) => { @@ -225,7 +226,8 @@ const findWorryListByTemplate = async(templateId: number,userId: number) => { export default { createWorry, updateWorry, - deleteWorry, + deleteWorryWithReview, + deleteWorryWithoutReview, findWorryById, createFinalAnswer, updateDeadline, diff --git a/src/service/worryService.ts b/src/service/worryService.ts index d73c6a5..0cf19ec 100644 --- a/src/service/worryService.ts +++ b/src/service/worryService.ts @@ -80,12 +80,13 @@ const deleteWorry =async (worryId: number,userId: number) => { if (worry.user_id != userId) { throw new ClientException("고민글 작성자만 삭제할 수 있습니다."); } - // const review = await reviewRepository.findreviewById(worryId); - // if(review){ - // await reviewRepository.deleteReviewById(worryId); - // } - await worryRepository.deleteWorry(worryId); + const review = await reviewRepository.findreviewById(worryId); + if(!review){ + return await worryRepository.deleteWorryWithoutReview(worryId); + } + + return await worryRepository.deleteWorryWithReview(worryId); } const getWorryDetail =async (worryId: number,userId: number) => {