Skip to content

Commit

Permalink
Merge pull request #125 from gsainfoteam/124-sgh
Browse files Browse the repository at this point in the history
modify: change return type of notice alarm
  • Loading branch information
GanghyeonSeo authored Nov 18, 2024
2 parents af8915c + 155a798 commit 7c9a736
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/notice/notice.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class NoticeController {
async sendNotice(
@GetUser() user: User,
@Param('id', ParseIntPipe) id: number,
): Promise<void> {
): Promise<ExpandedGeneralNoticeDto> {
return this.noticeService.sendNotice(id, user.uuid);
}

Expand Down
40 changes: 31 additions & 9 deletions src/notice/notice.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ export class NoticeService {
return notice;
}

async sendNotice(id: number, userUuid: string): Promise<void> {
async sendNotice(
id: number,
userUuid: string,
): Promise<ExpandedGeneralNoticeDto> {
const notice = await this.getNotice(id, { isViewed: false });
if (notice.author.uuid !== userUuid) {
throw new ForbiddenException('not author of the notice');
Expand All @@ -180,14 +183,33 @@ 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');
});

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;
}

async addNoticeAdditional(
Expand Down

0 comments on commit 7c9a736

Please sign in to comment.