From 1e527b63ead192b5ffe9143adb71de33b60eb0a7 Mon Sep 17 00:00:00 2001 From: SollyJ Date: Tue, 17 Jan 2023 22:23:21 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(api):=20add=20api=20for=20upda?= =?UTF-8?q?te=20PRP=20(#31)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/routes/v1/individual.ts | 24 ++++++++++++++++++++++-- src/services/individual.ts | 28 +++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/api/routes/v1/individual.ts b/src/api/routes/v1/individual.ts index e03f93e..0d4d60f 100644 --- a/src/api/routes/v1/individual.ts +++ b/src/api/routes/v1/individual.ts @@ -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( @@ -171,4 +191,4 @@ export default (app: Router) => { return res.status(200).json({ result: personalPost }); }), ); -}; +}; \ No newline at end of file diff --git a/src/services/individual.ts b/src/services/individual.ts index 9ae4342..ca8087d 100644 --- a/src/services/individual.ts +++ b/src/services/individual.ts @@ -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(