diff --git a/src/firebase.ts b/src/firebase.ts index b671021..2667c4b 100644 --- a/src/firebase.ts +++ b/src/firebase.ts @@ -4,33 +4,43 @@ import { fbConfig } from './fbconfig'; import { Department } from '../server/src/department/department.entity'; import { Notice } from '../server/src/notice/notice.entity'; import { parseTagsToStringWithSeparator } from './utils'; -import { messaging } from 'firebase-admin'; -import MessagingOptions = messaging.MessagingOptions; admin.initializeApp({ credential: admin.credential.cert(fbConfig) }); +const getPayload = (notice: Notice, department: Department, tags: string[]) => { + const previewLength = 250; + + return { + title: `${department.name} 신규 공지사항입니다`, + body: notice.title, + noticeId: `${notice.id}`, + departmentName: department.name, + departmentId: `${department.id}`, + preview: notice.contentText.slice(0, previewLength), + tags: parseTagsToStringWithSeparator(tags, ';'), + }; +}; + export async function sendNoticeCreationMessage( condition: string, notice: Notice, department: Department, tags: string[], ) { - const previewLength = 250; - - const payload = { - data: { - title: `${department.name} 신규 공지사항입니다`, - body: notice.title, - noticeId: `${notice.id}`, - departmentName: department.name, - departmentId: `${department.id}`, - preview: notice.contentText.slice(0, previewLength), - tags: parseTagsToStringWithSeparator(tags, ';'), + const testMessage = { + android: { + data: getPayload(notice, department, tags), }, + apns: { + payload: { + aps: { + alert: getPayload(notice, department, tags), + contentAvailable: true, + }, + customKey: 'customValue', + }, + }, + condition, }; - const options: MessagingOptions = { - contentAvailable: true, - }; - - await admin.messaging().sendToCondition(condition, payload, options); + await admin.messaging().send(testMessage); } diff --git a/src/routes/routeList.ts b/src/routes/routeList.ts index c012845..765c946 100644 --- a/src/routes/routeList.ts +++ b/src/routes/routeList.ts @@ -163,7 +163,7 @@ export const earlyStopList: Crawler[] = [ design, ]; -const populationList = [orientalpainting, painting, sculpture, craft, design, sociology]; +const populationList: Crawler[] = []; const POPULATION = TRUE_STRING.includes(process.env.POPULATION ?? ''); const crawlerList = POPULATION ? populationList : earlyStopList;