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

Fix/#172: 학과 공지사항 핸들링 에러 수정 #173

Merged
merged 2 commits into from
Jan 12, 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
2 changes: 1 addition & 1 deletion src/apis/notice/service.ts
Original file line number Diff line number Diff line change
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
6 changes: 4 additions & 2 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