diff --git a/src/interfaces/DTO/worryDTO.ts b/src/interfaces/DTO/worryDTO.ts index a58107f..02dc043 100644 --- a/src/interfaces/DTO/worryDTO.ts +++ b/src/interfaces/DTO/worryDTO.ts @@ -1,4 +1,4 @@ -import { IsString, IsDefined, IsNumber, IsArray, IsNotEmpty} from 'class-validator'; +import { IsString, IsDefined, IsNumber, IsArray, IsNotEmpty, isNumber} from 'class-validator'; class worryCreateDTO { @@ -28,6 +28,10 @@ class worryUpdateDTO{ @IsNumber() worryId!: number; + @IsDefined() + @IsNumber() + templateId!: number; + @IsDefined() @IsNumber() userId!: number; diff --git a/src/repository/worryRepository.ts b/src/repository/worryRepository.ts index 3e61e2b..92c0d8b 100644 --- a/src/repository/worryRepository.ts +++ b/src/repository/worryRepository.ts @@ -26,6 +26,7 @@ const updateWorry = async(worryUpdateDTO: worryUpdateDTO) => { id: worryUpdateDTO.worryId }, data: { + template_id: worryUpdateDTO.templateId, title: worryUpdateDTO.title, answers: worryUpdateDTO.answers, updated_at: new Date(), diff --git a/src/service/worryService.ts b/src/service/worryService.ts index 09b665a..921a7ff 100644 --- a/src/service/worryService.ts +++ b/src/service/worryService.ts @@ -47,8 +47,17 @@ const postWorry =async (worryCreateDTO: worryCreateDTO) => { } const patchWorry =async (worryUpdateDTO: worryUpdateDTO) => { - const worry = await worryRepository.updateWorry(worryUpdateDTO); + const worry = await worryRepository.findWorryById(worryUpdateDTO.worryId); + if (!worry) { + throw new ClientException("수정할 고민글이 존재하지 않습니다."); + } + if (worry.user_id != worryUpdateDTO.userId) { + throw new ClientException("고민글 작성자만 수정할 수 있습니다."); + } + + const updatedWorry = await worryRepository.updateWorry(worryUpdateDTO); + if (!updatedWorry) { throw new ClientException(rm.UPDATE_WORRY_FAIL); }