From 3277c2ddc26cc12c604a949a1c686debd1b77f9e Mon Sep 17 00:00:00 2001 From: GanghyeonSeo Date: Mon, 18 Nov 2024 15:29:46 +0900 Subject: [PATCH 1/3] modify: change return type of notice alarm --- src/notice/notice.controller.ts | 2 +- src/notice/notice.service.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/notice/notice.controller.ts b/src/notice/notice.controller.ts index 1e3d632..d90d50c 100644 --- a/src/notice/notice.controller.ts +++ b/src/notice/notice.controller.ts @@ -125,7 +125,7 @@ export class NoticeController { async sendNotice( @GetUser() user: User, @Param('id', ParseIntPipe) id: number, - ): Promise { + ): Promise { return this.noticeService.sendNotice(id, user.uuid); } diff --git a/src/notice/notice.service.ts b/src/notice/notice.service.ts index 30bfba3..f5415e4 100644 --- a/src/notice/notice.service.ts +++ b/src/notice/notice.service.ts @@ -164,7 +164,10 @@ export class NoticeService { return notice; } - async sendNotice(id: number, userUuid: string): Promise { + async sendNotice( + id: number, + userUuid: string, + ): Promise { const notice = await this.getNotice(id, { isViewed: false }); if (notice.author.uuid !== userUuid) { throw new ForbiddenException('not author of the notice'); @@ -188,6 +191,8 @@ export class NoticeService { }, ); await this.noticeRepository.updatePublishedAt(id, new Date()); + + return notice; } async addNoticeAdditional( From 10142479194074c1ad7dd30e7045e0d117db68cd Mon Sep 17 00:00:00 2001 From: GanghyeonSeo Date: Mon, 18 Nov 2024 16:10:09 +0900 Subject: [PATCH 2/3] modify: sequence of update publishedAt and send notification --- src/notice/notice.service.ts | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/notice/notice.service.ts b/src/notice/notice.service.ts index f5415e4..7657a9a 100644 --- a/src/notice/notice.service.ts +++ b/src/notice/notice.service.ts @@ -176,6 +176,16 @@ export class NoticeService { throw new ForbiddenException('a message already sent'); } + await this.noticeRepository + .updatePublishedAt(id, new Date()) + .catch((error) => { + this.logger.error( + `Failed to update publishedAt for notice ${id}: `, + error, + ); + throw new InternalServerErrorException('failed to update publishedAt'); + }); + const notification = { title: '[긴급] ' + notice.title, body: notice.content, @@ -183,14 +193,21 @@ export class NoticeService { }; await this.fcmService.deleteMessageJobIdPattern(notice.id.toString()); - await this.fcmService.postMessage( - this.convertNotificationBodyToString(notification), - FcmTargetUser.All, - { - path: `/notice/${id}`, - }, - ); - await this.noticeRepository.updatePublishedAt(id, new Date()); + await this.fcmService + .postMessage( + this.convertNotificationBodyToString(notification), + FcmTargetUser.All, + { + path: `/notice/${id}`, + }, + ) + .catch((error) => { + this.logger.error( + `Failed to send notification for notice ${id}: `, + error, + ); + throw new InternalServerErrorException('failed to send notification'); + }); return notice; } From 155a798e855773a46b7d8b2fae32842d22453682 Mon Sep 17 00:00:00 2001 From: GanghyeonSeo Date: Mon, 18 Nov 2024 16:51:32 +0900 Subject: [PATCH 3/3] modify: revert sequence of update publishedAt and send notification --- src/notice/notice.service.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/notice/notice.service.ts b/src/notice/notice.service.ts index 7657a9a..3d6dd11 100644 --- a/src/notice/notice.service.ts +++ b/src/notice/notice.service.ts @@ -176,16 +176,6 @@ export class NoticeService { throw new ForbiddenException('a message already sent'); } - await this.noticeRepository - .updatePublishedAt(id, new Date()) - .catch((error) => { - this.logger.error( - `Failed to update publishedAt for notice ${id}: `, - error, - ); - throw new InternalServerErrorException('failed to update publishedAt'); - }); - const notification = { title: '[긴급] ' + notice.title, body: notice.content, @@ -209,6 +199,16 @@ export class NoticeService { throw new InternalServerErrorException('failed to send notification'); }); + await this.noticeRepository + .updatePublishedAt(id, new Date()) + .catch((error) => { + this.logger.error( + `Failed to update publishedAt for notice ${id}: `, + error, + ); + throw new InternalServerErrorException('failed to update publishedAt'); + }); + return notice; }