From 3196426f1c12a8de754bb2295dc0acf9fcc07bcb Mon Sep 17 00:00:00 2001 From: hwinkr Date: Sat, 27 Jan 2024 19:03:29 +0900 Subject: [PATCH 1/8] =?UTF-8?q?Feat:=20=EA=B1=B4=EB=AC=BC=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20api=20=EB=9D=BC=EC=9A=B0=ED=8C=85=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 80496f8..be6c876 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,10 @@ +import buildingInfoRouter from '@apis/building-info/controllers'; import graduationRouter from '@apis/graduation/controller'; import majorRouter from '@apis/majorDecision/controller'; import noticeRouter from '@apis/notice/controller'; import subscriptionRouter from '@apis/subscribe/controller'; import suggestionRouter from '@apis/suggestion/controller'; import env from '@config'; -import { saveMajorNoticeToDB } from '@db/data/noticeHandler'; import { corsOptions } from '@middlewares/cors'; import errorHandler from '@middlewares/error-handler'; import cors from 'cors'; @@ -30,6 +30,7 @@ app.use('/api/majorDecision', majorRouter); app.use('/api/announcement', noticeRouter); app.use('/api/graduation', graduationRouter); app.use('/api/subscription', subscriptionRouter); +app.use('/api/buildingInfo', buildingInfoRouter); app.get('/test', (req: Request, res: Response) => { console.log('test'); From f06bf2e513a1c9bd9d98e8efc7d7234a786e2cf7 Mon Sep 17 00:00:00 2001 From: hwinkr Date: Sat, 27 Jan 2024 19:09:55 +0900 Subject: [PATCH 2/8] =?UTF-8?q?Feat:=20=EA=B1=B4=EB=AC=BC=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20api=20=EC=9A=94=EC=B2=AD=20=ED=9B=84,=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=ED=8F=AC=EB=A7=B7=ED=8C=85=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/building-info/service.ts | 99 +++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/apis/building-info/service.ts diff --git a/src/apis/building-info/service.ts b/src/apis/building-info/service.ts new file mode 100644 index 0000000..a95e4f4 --- /dev/null +++ b/src/apis/building-info/service.ts @@ -0,0 +1,99 @@ +import axios, { AxiosResponse } from 'axios'; +import notificationToSlack from 'src/hooks/notificateToSlack'; + +type Floor = 'basement' | 'ground' | 'rooftop'; + +interface Room { + roomNumber: string; + roomName: string; +} + +interface FormattedInfo extends Room { + floor: number; + floorType: Floor; +} + +type TotalInfo = { + [key in Floor]: { + [key in string]: Room[]; + }; +}; + +const configPaylod = (code: string) => { + const payload = new URLSearchParams(); + payload.append('code', code); + payload.append('stat', 'D'); + + return payload; +}; + +const handleLayerType = (layerType: string) => { + if (layerType === '0') return 'ground'; + if (layerType === '1') return 'basement'; + if (layerType === '2') return 'rooftop'; +}; + +const formatTotalInfo = (formattedInfo: FormattedInfo[]) => { + const totalInfo: TotalInfo = { + basement: {}, + ground: {}, + rooftop: {}, + }; + + formattedInfo.forEach(({ roomNumber, roomName, floor, floorType }) => { + const type = floorType as Floor; + + if (!Object.prototype.hasOwnProperty.call(totalInfo[type], floor)) { + totalInfo[type][floor] = [{ roomNumber, roomName }]; + return; + } + + totalInfo[type][floor].push({ roomNumber, roomName }); + }); + + return totalInfo; +}; + +const formatFetchedInfo = (data: AxiosResponse['data']) => { + const formattedData: FormattedInfo[] = data.response.deps2.reduce( + (accData: FormattedInfo[], curr: any) => { + const item = { + roomNumber: curr.roomNo, + roomName: curr.roomName, + floor: curr.layer, + floorType: handleLayerType(curr.layerTyp), + }; + + return [...accData, item]; + }, + [] as FormattedInfo[], + ); + + const formattedInfo = formatTotalInfo(formattedData); + + return formattedInfo; +}; + +const fetchBuildingInfo = async (code: string) => { + const REQUEST_URL = 'https://www.pknu.ac.kr/buildingInfoAjax.do'; + const HEADERS = { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36', + }; + const payload = configPaylod(code); + + try { + const response = await axios.post(REQUEST_URL, payload.toString(), { + headers: HEADERS, + }); + + const formattedInfo = formatFetchedInfo(response.data); + + return formattedInfo; + } catch (error) { + notificationToSlack('건물 정보 요청에 문제가 발생했습니다.'); + console.log(error); + } +}; + +export default fetchBuildingInfo; From 584fb7cd1dec4aff89c58ed222f8457559a6ac70 Mon Sep 17 00:00:00 2001 From: hwinkr Date: Sat, 27 Jan 2024 19:10:21 +0900 Subject: [PATCH 3/8] =?UTF-8?q?Feat:=20=EA=B1=B4=EB=AC=BC=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20api=20=EB=9D=BC=EC=9A=B0=ED=8C=85=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/building-info/controllers.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/apis/building-info/controllers.ts diff --git a/src/apis/building-info/controllers.ts b/src/apis/building-info/controllers.ts new file mode 100644 index 0000000..1ef0448 --- /dev/null +++ b/src/apis/building-info/controllers.ts @@ -0,0 +1,18 @@ +import express, { Request, Response } from 'express'; + +import fetchBuildingInfo from './service'; + +const router = express.Router(); + +router.get('/', async (req: Request, res: Response) => { + const code = req.query.code; + + try { + const buildingInfo = await fetchBuildingInfo(code as string); + res.json(buildingInfo); + } catch (err) { + console.log(err); + } +}); + +export default router; From 6aa4b4f45ff681aab97ea163189cebf5ecf0f552 Mon Sep 17 00:00:00 2001 From: Lee sang Yeop Date: Sun, 4 Feb 2024 19:00:32 +0900 Subject: [PATCH 4/8] =?UTF-8?q?fix(majorUtils=20getDepartmentIdByMajor):?= =?UTF-8?q?=20=EB=8D=94=20=EC=9C=A0=EC=97=B0=ED=95=98=EA=B2=8C=20=ED=95=99?= =?UTF-8?q?=EA=B3=BC=20ID=20=EA=B0=92=EC=9D=84=20=EA=B5=AC=ED=95=A0=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/majorUtils.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/utils/majorUtils.ts b/src/utils/majorUtils.ts index 70cfbcd..5f8eb4e 100644 --- a/src/utils/majorUtils.ts +++ b/src/utils/majorUtils.ts @@ -2,10 +2,7 @@ import { selectQuery } from '@db/query/dbQueryHandler'; import notificationToSlack from 'src/hooks/notificateToSlack'; export const getDepartmentIdByMajor = async (major: string) => { - const [departmentName, departmentSubName] = major.split(' '); - const getDepartmentQuery = `SELECT id FROM departments WHERE department_name = '${departmentName}' ${ - departmentSubName ? `AND department_subname = '${departmentSubName}'` : '' - };`; + const getDepartmentQuery = `SELECT id FROM departments WHERE department_name = '${major}' OR department_subname = '${major}'`; try { const departmentId = await selectQuery<{ id: number }[]>( From 0941ac8eabcff5d7d43f447f0d0e8a3d9a36e9ab Mon Sep 17 00:00:00 2001 From: Lee sang Yeop Date: Sun, 4 Feb 2024 21:14:00 +0900 Subject: [PATCH 5/8] =?UTF-8?q?fix(noticeHandler):=20=ED=95=99=EA=B3=BC=20?= =?UTF-8?q?=EA=B3=B5=EC=A7=80=EC=82=AC=ED=95=AD=20=ED=81=AC=EB=A1=A4?= =?UTF-8?q?=EB=A7=81=EC=9D=84=20=EB=B9=84=EB=8F=99=EA=B8=B0=EB=A1=9C=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EB=B9=84=EB=8F=99=EA=B8=B0=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=9D=B4=EC=99=B8=EC=97=90=EB=8F=84=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=EC=97=90=20=ED=95=A8=EC=88=98=EB=8B=A8=EC=9C=84=EC=9D=98=20?= =?UTF-8?q?=ED=8A=B8=EB=9E=9C=EC=9E=AD=EC=85=98=EC=9D=84=20=ED=95=99?= =?UTF-8?q?=EA=B3=BC=20=EB=8B=A8=EC=9C=84=EC=9D=98=20=ED=8A=B8=EB=9E=9C?= =?UTF-8?q?=EC=9E=AD=EC=85=98=EC=9C=BC=EB=A1=9C=20=EC=B6=95=EC=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/data/noticeHandler.ts | 131 ++++++++++++++++++++++------------- 1 file changed, 83 insertions(+), 48 deletions(-) diff --git a/src/db/data/noticeHandler.ts b/src/db/data/noticeHandler.ts index 1a26e14..b6ef790 100644 --- a/src/db/data/noticeHandler.ts +++ b/src/db/data/noticeHandler.ts @@ -17,6 +17,7 @@ export interface PushNoti { interface NotiLink { link: string; + rep_yn: boolean; } export const saveDepartmentToDB = async (college: College[]): Promise => { @@ -74,79 +75,113 @@ const convertAllNoticeToNormalNotice = async ( } }; -const convertSpecificNoticeToPinnedNotice = async ( +const convertSpecificNoticePinned = async ( tableName: string, noticeLink: string, + isPinned: boolean, + connection?: PoolConnection, ): Promise => { - const query = `UPDATE ${tableName} SET rep_yn = true WHERE link = '${noticeLink}';`; + const query = `UPDATE ${tableName} SET rep_yn = ${isPinned} WHERE link = '${noticeLink}';`; try { - await db.execute(query); + if (connection) await connection.execute(query); + else await db.execute(query); } catch (error) { console.log(error.message + '고정 공지로 변경 실패'); // notificationToSlack(error.message + '\n 고정 공지로 변경 실패'); } }; -export const saveMajorNoticeToDB = async ( - connection?: PoolConnection, -): Promise => { - await convertAllNoticeToNormalNotice('major_notices', connection); +export const saveMajorNoticeToDB = async (): Promise => { + // await convertAllNoticeToNormalNotice('major_notices', connection); const query = 'SELECT * FROM departments;'; - const colleges = await selectQuery(query, connection); - - const getNotiLinkQuery = `SELECT link FROM major_notices;`; - const noticeLinksInDB = ( - await selectQuery(getNotiLinkQuery, connection) - ).map((noticeLink) => noticeLink.link); + const colleges = await selectQuery(query); - const savePromises: Promise[] = []; const newNoticeMajor: PushNoti = {}; + const failedMajor: number[] = []; - for (const college of colleges) { - console.log(college.id); - const noticeLink = await noticeCrawling(college); - const noticeLists = await noticeListCrawling(noticeLink); - - const normalNotices = noticeLists.normalNotice; - const pinnedNotices = noticeLists.pinnedNotice; - - if (normalNotices.length === 0) { - notificationToSlack(`${noticeLink} 크롤링 실패`); - continue; - } - - for (const notice of normalNotices) { - const result = await noticeContentCrawling(notice); - if (result.link === '') { - // notificationToSlack(`${notice} 콘텐츠 크롤링 실패`); - continue; + const savePromises = colleges.map(async (college) => { + const connection = await db.getConnection(); + await connection.beginTransaction(); + try { + console.log(college.id); + const noticeLink = await noticeCrawling(college); + const noticeLists = await noticeListCrawling(noticeLink); + const normalNotices = noticeLists.normalNotice; + const pinnedNotices = noticeLists.pinnedNotice; + const getNotiLinkQuery = `SELECT link, rep_yn FROM major_notices WHERE department_id = '${college.id}'`; + const noticeDataInDB = await selectQuery( + getNotiLinkQuery, + connection, + ); + const noticeLinksInDB = noticeDataInDB.map((noti) => noti.link); + const pinnedNoticeLinksInDB = noticeDataInDB + .filter((noti) => noti.rep_yn === true) + .map((noti) => noti.link); + + if (normalNotices.length === 0) { + notificationToSlack(`${noticeLink} 크롤링 실패`); + connection.release(); + return; } - if (noticeLinksInDB.includes(result.link)) continue; - if (!newNoticeMajor[college.id]) newNoticeMajor[college.id] = []; - newNoticeMajor[college.id].push(result.title); - savePromises.push(saveMajorNotice(result, college.id, false, connection)); - } - - if (pinnedNotices) { - for (const notice of pinnedNotices) { + for (const notice of normalNotices) { const result = await noticeContentCrawling(notice); if (result.link === '') { - notificationToSlack(`${notice} 콘텐츠 크롤링 실패`); + // notificationToSlack(`${notice} 콘텐츠 크롤링 실패`); continue; } - if (!noticeLinksInDB.includes(result.link)) { - savePromises.push( - saveMajorNotice(result, college.id, true, connection), + if (noticeLinksInDB.includes(result.link)) return; + if (!newNoticeMajor[college.id]) newNoticeMajor[college.id] = []; + newNoticeMajor[college.id].push(result.title); + saveMajorNotice(result, college.id, false, connection); + noticeLinksInDB.push(result.link); + } + + if (pinnedNotices) { + await pinnedNoticeLinksInDB + .filter((noti) => !pinnedNotices.includes(noti)) + .map( + async (noti) => + await convertSpecificNoticePinned( + 'major_notices', + noti, + false, + connection, + ), ); - continue; + for (const notice of pinnedNotices) { + const result = await noticeContentCrawling(notice); + if (result.link === '') { + notificationToSlack(`${notice} 콘텐츠 크롤링 실패`); + continue; + } + + if (!noticeLinksInDB.includes(result.link)) { + saveMajorNotice(result, college.id, true, connection); + continue; + } + + if (!pinnedNoticeLinksInDB.includes(result.link)) + convertSpecificNoticePinned( + 'major_notices', + result.link, + true, + connection, + ); } - convertSpecificNoticeToPinnedNotice('major_notices', result.link); } + + connection.commit(); + } catch (error) { + notificationToSlack(college.id + '크롤링 실패' + error.message); + failedMajor.push(college.id); + connection.rollback(); + } finally { + connection.release(); } - } + }); await Promise.all(savePromises); return newNoticeMajor; @@ -188,7 +223,7 @@ export const saveSchoolNoticeToDB = async (): Promise => { for (const noticeLink of pinnedNotices) { if (schoolNoticeLinksInDB.includes(noticeLink)) { - await convertSpecificNoticeToPinnedNotice('notices', noticeLink); + await convertSpecificNoticePinned('notices', noticeLink, true); continue; } From a4685c202386cc53f258ac679c968c63f1122cc8 Mon Sep 17 00:00:00 2001 From: Lee sang Yeop Date: Sun, 4 Feb 2024 21:20:03 +0900 Subject: [PATCH 6/8] =?UTF-8?q?fix(cronNoticeCrawling):=20=ED=81=AC?= =?UTF-8?q?=EB=A1=A0=20=EB=8F=99=EC=9E=91=20=EC=8B=9C=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=20=EB=B0=9C=EC=83=9D=ED=95=98=EB=A9=B4=203=EB=B2=88=EA=B9=8C?= =?UTF-8?q?=EC=A7=80=20=EB=8F=99=EC=9E=91=ED=95=9C=20=ED=9B=84=20=EC=A2=85?= =?UTF-8?q?=EB=A3=8C=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EB=A7=8C=EC=95=BD=20=EB=8F=84=EC=A4=91=EC=97=90=20=ED=83=88?= =?UTF-8?q?=EC=B6=9C=ED=95=98=EC=A7=80=20=EC=95=8A=EC=9C=BC=EB=A9=B4=20?= =?UTF-8?q?=EB=AC=B4=ED=95=9C=20=EB=A3=A8=ED=94=84=EB=A1=9C=20=EC=9D=B8?= =?UTF-8?q?=ED=95=B4=20=EC=84=9C=EB=B2=84=EC=97=90=20=EC=95=88=EC=A2=8B?= =?UTF-8?q?=EC=9D=80=20=EC=98=81=ED=96=A5=20=EB=98=90=EB=8A=94=20=EB=AC=B4?= =?UTF-8?q?=ED=95=9C=20=EC=8A=AC=EB=9E=99=20=EC=95=8C=EB=A6=BC=EC=9D=84=20?= =?UTF-8?q?=EB=B0=9B=EA=B8=B0=EC=97=90=203=ED=9A=8C=EA=B9=8C=EC=A7=80=20?= =?UTF-8?q?=EC=8B=9C=EB=8F=84=20=ED=9B=84=20=EC=A2=85=EB=A3=8C=EB=90=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EC=A0=81=EC=9C=BC=EB=A1=9C=20=ED=81=AC=EB=A1=A0=20=EB=82=B4?= =?UTF-8?q?=EB=B6=80=EC=97=90=EC=84=9C=20=ED=8A=B8=EB=9E=9C=EC=9E=AD?= =?UTF-8?q?=EC=85=98=EC=9D=84=20=EC=83=9D=EC=84=B1=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/cronNoticeCrawling.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/hooks/cronNoticeCrawling.ts b/src/hooks/cronNoticeCrawling.ts index d8ced5e..b1f0831 100644 --- a/src/hooks/cronNoticeCrawling.ts +++ b/src/hooks/cronNoticeCrawling.ts @@ -21,34 +21,34 @@ const pushToUsers = async (pushNotiToUserLists: PushNoti) => { if (pushedUserCount.length !== 0) notificationToSlack(pushedUserCount); }; -const cronNoticeCrawling = async () => { - const connection = await db.getConnection(); - await connection.beginTransaction(); +const cronNoticeCrawling = async (reTryCount = 0) => { try { - const pushNotiToUserLists = await saveMajorNoticeToDB(connection); + const pushNotiToUserLists = await saveMajorNoticeToDB(); const today = new Date(); const year = today.getFullYear(); const month = today.getMonth() + 1; // 월은 0부터 시작하므로 1을 더해줍니다. const day = today.getDate(); notificationToSlack(`${year}-${month}-${day} 크롤링 완료`); - await connection.commit(); pushToUsers(pushNotiToUserLists); } catch (error) { - await connection.rollback(); - notificationToSlack(error.message); - cronNoticeCrawling(); - } finally { - connection.release(); + if (reTryCount >= 2) { + notificationToSlack(error.message); + return; + } + cronNoticeCrawling(reTryCount + 1); } }; -const cronExtracurricularCrawling = async () => { +const cronExtracurricularCrawling = async (reTryCount = 0) => { try { await saveSchoolNoticeToDB(); await saveLanguageNoticeToDB(); await saveWhalebeToDB(); } catch (error) { - notificationToSlack(error.message); + if (reTryCount >= 2) { + notificationToSlack(error.message); + return; + } cronExtracurricularCrawling(); } }; From 2daf2b601f8b841f279a1f05f05897b647f29367 Mon Sep 17 00:00:00 2001 From: Lee sang Yeop Date: Sun, 4 Feb 2024 21:21:07 +0900 Subject: [PATCH 7/8] =?UTF-8?q?feat(noticeHandler):=20=EC=98=88=EA=B8=B0?= =?UTF-8?q?=EC=B9=98=20=EB=AA=BB=ED=95=9C=20=EC=97=90=EB=9F=AC=EB=A1=9C=20?= =?UTF-8?q?=EA=B3=B5=EC=A7=80=EC=8B=9C=ED=95=AD=20=ED=81=AC=EB=A1=A4?= =?UTF-8?q?=EB=A7=81=20=EC=8B=A4=ED=8C=A8=ED=95=9C=20=ED=95=99=EA=B3=BC?= =?UTF-8?q?=EB=8A=94=20=EC=8A=AC=EB=9E=99=20=EC=95=8C=EB=A6=BC=EC=9D=84=20?= =?UTF-8?q?=EB=B0=9B=EB=8F=84=EB=A1=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/data/noticeHandler.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/db/data/noticeHandler.ts b/src/db/data/noticeHandler.ts index b6ef790..688edce 100644 --- a/src/db/data/noticeHandler.ts +++ b/src/db/data/noticeHandler.ts @@ -184,6 +184,11 @@ export const saveMajorNoticeToDB = async (): Promise => { }); await Promise.all(savePromises); + if (failedMajor.length !== 0) { + const failedMajorList = failedMajor.join(); + notificationToSlack('크롤링 실패한 학과: ' + failedMajorList); + } + return newNoticeMajor; }; From 708e1c62c23ac775e24b3f3264dc15be271155b6 Mon Sep 17 00:00:00 2001 From: Lee sang Yeop Date: Mon, 5 Feb 2024 18:16:22 +0900 Subject: [PATCH 8/8] =?UTF-8?q?fix(noticeHandler):=20=ED=94=BC=EB=93=9C?= =?UTF-8?q?=EB=B0=B1=20=EB=82=B4=EC=9A=A9=20=EB=B0=98=EC=98=81=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EC=BD=98=EC=86=94=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=20=EC=A0=9C=EA=B1=B0=20=EC=96=BC=EB=A6=AC=20=EB=A6=AC?= =?UTF-8?q?=ED=84=B4=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD=20=ED=95=84?= =?UTF-8?q?=ED=84=B0=20=EC=A1=B0=EA=B1=B4=20=EA=B0=84=EA=B2=B0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/data/noticeHandler.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/db/data/noticeHandler.ts b/src/db/data/noticeHandler.ts index 688edce..9f6b543 100644 --- a/src/db/data/noticeHandler.ts +++ b/src/db/data/noticeHandler.ts @@ -104,11 +104,16 @@ export const saveMajorNoticeToDB = async (): Promise => { const connection = await db.getConnection(); await connection.beginTransaction(); try { - console.log(college.id); const noticeLink = await noticeCrawling(college); const noticeLists = await noticeListCrawling(noticeLink); - const normalNotices = noticeLists.normalNotice; const pinnedNotices = noticeLists.pinnedNotice; + const normalNotices = noticeLists.normalNotice; + if (normalNotices.length === 0) { + notificationToSlack(`${noticeLink} 크롤링 실패`); + connection.release(); + return; + } + const getNotiLinkQuery = `SELECT link, rep_yn FROM major_notices WHERE department_id = '${college.id}'`; const noticeDataInDB = await selectQuery( getNotiLinkQuery, @@ -116,15 +121,9 @@ export const saveMajorNoticeToDB = async (): Promise => { ); const noticeLinksInDB = noticeDataInDB.map((noti) => noti.link); const pinnedNoticeLinksInDB = noticeDataInDB - .filter((noti) => noti.rep_yn === true) + .filter((noti) => noti.rep_yn) .map((noti) => noti.link); - if (normalNotices.length === 0) { - notificationToSlack(`${noticeLink} 크롤링 실패`); - connection.release(); - return; - } - for (const notice of normalNotices) { const result = await noticeContentCrawling(notice); if (result.link === '') {