Skip to content

Commit

Permalink
[FIX] review가 없는경우 delete review, delete worry transaction불가 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
leGit-y committed Nov 22, 2023
1 parent 8ed981f commit 76fea71
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
20 changes: 11 additions & 9 deletions src/repository/worryRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:{
Expand All @@ -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) => {

Expand Down Expand Up @@ -225,7 +226,8 @@ const findWorryListByTemplate = async(templateId: number,userId: number) => {
export default {
createWorry,
updateWorry,
deleteWorry,
deleteWorryWithReview,
deleteWorryWithoutReview,
findWorryById,
createFinalAnswer,
updateDeadline,
Expand Down
11 changes: 6 additions & 5 deletions src/service/worryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 76fea71

Please sign in to comment.