Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

부리미 서버 1.08v 배포 #174

Merged
merged 11 commits into from
Jan 15, 2024
Merged
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
14 changes: 9 additions & 5 deletions src/apis/notice/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import notificationToSlack from 'src/hooks/notificateToSlack';
import { getDepartmentIdByMajor } from 'src/utils/majorUtils';

interface SeparateNoti {
고정: ResponseNotice[] | Notices[];
일반: ResponseNotice[] | Notices[];
고정: ResponseNotice[] | Notices[] | RecruitData[];
일반: ResponseNotice[] | Notices[] | RecruitData[];
}

export interface ResponseNotice {
Expand Down Expand Up @@ -43,7 +43,7 @@ const updateNotice = (notices: Notices[]) => {

export const getNotices = async (department: string): Promise<SeparateNoti> => {
const majorId = await getDepartmentIdByMajor(department);
const query = `SELECT * FROM major_notices WHERE department_id = ${majorId};`;
const query = `SELECT * FROM major_notices WHERE department_id = ${majorId} ORDER BY STR_TO_DATE(upload_date, '%Y-%m-%d') DESC;`;
const major_notices = await selectQuery<Notices[]>(query);

const notices: SeparateNoti = {
Expand Down Expand Up @@ -98,14 +98,18 @@ export const getLanguage = async (): Promise<SeparateNoti> => {
return notices;
};

export const getRecruit = async (): Promise<RecruitData[]> => {
export const getRecruit = async (): Promise<SeparateNoti> => {
const query = 'SELECT * FROM recruit_notices;';
const recruitNotices = await selectQuery<RecruitData[]>(query);
recruitNotices.sort(
(notice1, notice2) =>
new Date(notice2.recruitment_period.split('~')[0]).getTime() -
new Date(notice1.recruitment_period.split('~')[0]).getTime(),
);
const notices: SeparateNoti = {
일반: recruitNotices,
고정: [],
};

return recruitNotices;
return notices;
};
2 changes: 2 additions & 0 deletions src/apis/subscribe/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@ export const pushNotification = async (
}
}
}

return subscribeUsers.length;
};
15 changes: 11 additions & 4 deletions src/db/data/noticeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ const saveMajorNotice = async (

const convertAllNoticeToNormalNotice = async (
tableName: string,
connection?: PoolConnection,
): Promise<void> => {
const query = `UPDATE ${tableName} SET rep_yn = false;`;

try {
await db.execute(query);
if (connection) await connection.execute(query);
else await db.execute(query);
console.log('모든 공지를 일반 공지로 변경');
} catch (error) {
notificationToSlack(error.message + '\n모든 공지를 일반 공지로 변경 실패');
Expand All @@ -89,7 +91,7 @@ const convertSpecificNoticeToPinnedNotice = async (
export const saveMajorNoticeToDB = async (
connection?: PoolConnection,
): Promise<PushNoti> => {
await convertAllNoticeToNormalNotice('major_notices');
await convertAllNoticeToNormalNotice('major_notices', connection);
const query = 'SELECT * FROM departments;';
const colleges = await selectQuery<College[]>(query, connection);

Expand Down Expand Up @@ -208,7 +210,7 @@ export const saveWhalebeToDB = async (): Promise<void> => {
const whalebeDatas = await whalebeCrawling();

// TODO: 웨일비 크롤링하는 데이터 추가해야함
const promises = whalebeDatas.map((data) => {
const promises = whalebeDatas.map(async (data) => {
const values = [
data.title,
data.link,
Expand All @@ -217,7 +219,12 @@ export const saveWhalebeToDB = async (): Promise<void> => {
data.imgurl,
];

return db.execute(query, values);
try {
const result = await db.execute(query, values);
return result;
} catch (error) {
console.log(error.message);
}
});

Promise.all(promises);
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/notificateToSlack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const notificationToSlack = async (text: string): Promise<void> => {
text,
});
} catch (error) {
console.error(error);
console.error(error.message);
return notificationToSlack(text);
}
return;
};
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const handleDeployToServer = async () => {
// 이 함수는 현재 배포되어있는 서버를 위해 사용되는 로직이며 최초 서버에 배포되는 1회만 실행되도록 하기위한 함수에요
// 그렇기에 아래에 작성된 코드들은 배포서버에 배포되면 다음 배포전 수정해주세요!!
// 전공 관련 크롤링
await saveMajorNoticeToDB();
};

handleDeployToServer();
// handleDeployToServer();