Skip to content

Commit

Permalink
fix(noticeHandler): 피드백 내용 반영
Browse files Browse the repository at this point in the history
불필요한 콘솔 로그 제거
얼리 리턴 위치 변경
필터 조건 간결화
  • Loading branch information
pp449 committed Feb 5, 2024
1 parent 2daf2b6 commit 708e1c6
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/db/data/noticeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,26 @@ export const saveMajorNoticeToDB = async (): Promise<PushNoti> => {
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<NotiLink[]>(
getNotiLinkQuery,
connection,
);
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 === '') {
Expand Down

0 comments on commit 708e1c6

Please sign in to comment.