Skip to content

Commit

Permalink
[FIX] patch worry에서 templateId 도 수정할 수 있게
Browse files Browse the repository at this point in the history
  • Loading branch information
leGit-y committed Oct 27, 2023
1 parent 6eb955f commit 1bf568b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/interfaces/DTO/worryDTO.ts
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -28,6 +28,10 @@ class worryUpdateDTO{
@IsNumber()
worryId!: number;

@IsDefined()
@IsNumber()
templateId!: number;

@IsDefined()
@IsNumber()
userId!: number;
Expand Down
1 change: 1 addition & 0 deletions src/repository/worryRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
11 changes: 10 additions & 1 deletion src/service/worryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 1bf568b

Please sign in to comment.