diff --git a/src/apis/subscribe/service.ts b/src/apis/subscribe/service.ts index 7624d726..b915c988 100644 --- a/src/apis/subscribe/service.ts +++ b/src/apis/subscribe/service.ts @@ -57,6 +57,7 @@ export const unsubscribeMajor = async ( if (error) { console.error('구독취소 실패'); reject(false); + return; } console.log('구독취소 성공'); resolve(true); @@ -74,7 +75,10 @@ export const pushNotification = ( const query = `SELECT user FROM ${major}구독`; return new Promise((resolve) => { db.query(query, async (err: Error, res: SubscribeUser[]) => { - if (err) console.error(err); + if (err) { + console.error(err); + return; + } if (res.length === 0) { resolve(0); diff --git a/src/db/data/noticeHandler.ts b/src/db/data/noticeHandler.ts index 67155968..7764eb52 100644 --- a/src/db/data/noticeHandler.ts +++ b/src/db/data/noticeHandler.ts @@ -9,6 +9,10 @@ import { College, Notice } from 'src/@types/college'; import db from 'src/db'; import notificationToSlack from 'src/hooks/notificateToSlack'; +export interface PushNoti { + [key: string]: string[]; +} + export const saveDepartmentToDB = async (college: College[]): Promise => { const saveCollegePromises = college.map((data) => { const saveCollegeQuery = `INSERT INTO departments (collegeName, departmentName, departmentSubName, departmentLink) VALUES ('${data.collegeName}', '${data.departmentName}', '${data.departmentSubName}', '${data.departmentLink}');`; @@ -46,7 +50,7 @@ const saveNotice = (notice: Notice, major: string): Promise => { }); }; -export const saveNoticeToDB = async (): Promise => { +export const saveNoticeToDB = async (): Promise => { const selectQuery = 'SELECT * FROM departments;'; const results = await new Promise((resolve) => { db.query(selectQuery, (error, results) => { @@ -60,7 +64,7 @@ export const saveNoticeToDB = async (): Promise => { }); const savePromises: Promise[] = []; - const newNoticeMajor: string[] = []; + const newNoticeMajor: PushNoti = {}; for (const row of results) { const college: College = { @@ -105,7 +109,6 @@ export const saveNoticeToDB = async (): Promise => { continue; } if (!pinnedNotiLink.includes(result.path)) { - if (!newNoticeMajor.includes(major)) newNoticeMajor.push(major); savePromises.push(saveNotice(result, major + '고정')); } } @@ -132,7 +135,8 @@ export const saveNoticeToDB = async (): Promise => { } if (!normalNotiLink.includes(result.path)) { - if (!newNoticeMajor.includes(major)) newNoticeMajor.push(major); + if (!newNoticeMajor[major]) newNoticeMajor[major] = []; + newNoticeMajor[major].push(result.title); savePromises.push(saveNotice(result, major + '일반')); } }