Skip to content

Commit

Permalink
✨ feat(api): add api for update PRP (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
SollyJ authored Jan 17, 2023
1 parent dc42a6e commit 1e527b6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
24 changes: 22 additions & 2 deletions src/api/routes/v1/individual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,27 @@ export default (app: Router) => {
);

// 개인 롤링페이퍼 수정
// TODO
route.put(
"/papers",
asyncHandler(
async (req: Request, res: Response) => {
logger.debug(req.body);

// 비즈니스 로직을 처리할 service객체 받아오기
const personalServiceInstance = Container.get(PersonalService);

const { updatedPersonalRollingPaper } = await personalServiceInstance.updatePersonalRollingPaper(
req.body as PersonalRollingPaperInputDTO,
req.body as PersonalRollingPaperDTO,
);

return res
.status(201)
.json({ result: "Rolling Paper updated", title: updatedPersonalRollingPaper.title, public_type: updatedPersonalRollingPaper.publicType});
},
),
);


// 개인 롤링페이퍼 삭제
route.delete(
Expand Down Expand Up @@ -171,4 +191,4 @@ export default (app: Router) => {
return res.status(200).json({ result: personalPost });
}),
);
};
};
28 changes: 27 additions & 1 deletion src/services/individual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,33 @@ export default class PersonalService {
}

// 개인 롤링페이퍼 수정해주는 함수
// TODO
public async updatePersonalRollingPaper(
personalRollingPaperInputDTO: PersonalRollingPaperInputDTO,
personalRollingPaperDTO: PersonalRollingPaperDTO,
): Promise<{ updatedPersonalRollingPaper: PersonalRollingPaper }> {
try {
const personalRollingPaperId =
personalRollingPaperInputDTO.paperId;

const updatedPersonalRollingPaper = await this.personalRollingPaperModel.update(
{
title: personalRollingPaperDTO.title,
public_type: personalRollingPaperDTO.publicType,
},
{ where: { personal_rolling_paper_id: personalRollingPaperId } },
);

if(!updatedPersonalRollingPaper) {
throw new Error("Unable to update paper");
}

return { updatedPersonalRollingPaper };
} catch (error) {
this.logger.error(error);
throw error;
}
}


// 개인 롤링페이퍼 삭제해주는 함수
public async deletePersonalRollingPaper(
Expand Down

0 comments on commit 1e527b6

Please sign in to comment.