Skip to content

Commit

Permalink
feat: send fcm if there are new academic notice
Browse files Browse the repository at this point in the history
  • Loading branch information
2paperstar committed Nov 24, 2023
1 parent 1d06c36 commit e508f3a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/notice/notice.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class NoticeService {
);
}

@Cron('*/20 * * * *')
@Cron('*/5 * * * *')
async crawlAcademicNotice() {
const recentNotice = await this.noticeRepository.getNoticeList({
limit: 1,
Expand All @@ -295,7 +295,7 @@ export class NoticeService {
const user = await this.userService.addTempUser(
`${meta.author} (${meta.category})`,
);
await this.noticeRepository.createNotice(
const result = await this.noticeRepository.createNotice(
{
title: meta.title,
body,
Expand All @@ -305,6 +305,13 @@ export class NoticeService {
user.uuid,
dayjs(meta.createdAt).tz('Asia/Seoul').toDate(),
);
await this.fcmService.postMessage(
{ title: '새 공지글', body: meta.title },
(
await this.noticeRepository.getAllFcmTokens()
).map(({ token }) => token),
{ path: `/root/article?id=${result.id}` },
);
}),
);
await lastValueFrom(concat($, of(null)));
Expand Down

0 comments on commit e508f3a

Please sign in to comment.