Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions src/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/routes/routeList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down