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) => {