Skip to content

Commit

Permalink
Merge pull request #132 from GDSC-PKNU-Official/fix/#131
Browse files Browse the repository at this point in the history
Fix/#131: 누락된 코드 롤백
  • Loading branch information
pp449 authored Oct 10, 2023
2 parents 81bc862 + 8533174 commit f60ba9b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/apis/subscribe/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const unsubscribeMajor = async (
if (error) {
console.error('구독취소 실패');
reject(false);
return;
}
console.log('구독취소 성공');
resolve(true);
Expand All @@ -74,7 +75,10 @@ export const pushNotification = (
const query = `SELECT user FROM ${major}구독`;
return new Promise<number>((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);
Expand Down
12 changes: 8 additions & 4 deletions src/db/data/noticeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
const saveCollegePromises = college.map((data) => {
const saveCollegeQuery = `INSERT INTO departments (collegeName, departmentName, departmentSubName, departmentLink) VALUES ('${data.collegeName}', '${data.departmentName}', '${data.departmentSubName}', '${data.departmentLink}');`;
Expand Down Expand Up @@ -46,7 +50,7 @@ const saveNotice = (notice: Notice, major: string): Promise<void> => {
});
};

export const saveNoticeToDB = async (): Promise<string[]> => {
export const saveNoticeToDB = async (): Promise<PushNoti> => {
const selectQuery = 'SELECT * FROM departments;';
const results = await new Promise<College[]>((resolve) => {
db.query(selectQuery, (error, results) => {
Expand All @@ -60,7 +64,7 @@ export const saveNoticeToDB = async (): Promise<string[]> => {
});

const savePromises: Promise<void>[] = [];
const newNoticeMajor: string[] = [];
const newNoticeMajor: PushNoti = {};

for (const row of results) {
const college: College = {
Expand Down Expand Up @@ -105,7 +109,6 @@ export const saveNoticeToDB = async (): Promise<string[]> => {
continue;
}
if (!pinnedNotiLink.includes(result.path)) {
if (!newNoticeMajor.includes(major)) newNoticeMajor.push(major);
savePromises.push(saveNotice(result, major + '고정'));
}
}
Expand All @@ -132,7 +135,8 @@ export const saveNoticeToDB = async (): Promise<string[]> => {
}

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 + '일반'));
}
}
Expand Down

0 comments on commit f60ba9b

Please sign in to comment.