diff --git a/.gitignore b/.gitignore index 0eee4ab3..2b6079a9 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ dist-ssr .env* .flaskenv* !.env.project -!.env.vault \ No newline at end of file +!.env.vault +tmp \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 3defb831..1645fe39 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,6 +36,7 @@ services: - --collation-server=utf8mb4_unicode_ci volumes: - ./sqls:/docker-entrypoint-initdb.d + - ./tmp:/var/lib/mysql networks: mysql_db: diff --git a/src/apis/notice/controller.ts b/src/apis/notice/controller.ts index dc130cad..9b77b25d 100644 --- a/src/apis/notice/controller.ts +++ b/src/apis/notice/controller.ts @@ -1,4 +1,9 @@ -import { getNotices, getSchoolNotices, getWhalebe } from '@apis/notice/service'; +import { + getLanguage, + getNotices, + getSchoolNotices, + getWhalebe, +} from '@apis/notice/service'; import express, { Request, Response } from 'express'; const router = express.Router(); @@ -26,4 +31,13 @@ router.get('/whalebe', async (req: Request, res: Response) => { } }); +router.get('/language', async (req: Request, res: Response) => { + try { + const languageNoti = await getLanguage(); + res.json(languageNoti); + } catch (err) { + res.json(); + } +}); + export default router; diff --git a/src/apis/notice/service.ts b/src/apis/notice/service.ts index cb6718f6..86b5fe5b 100644 --- a/src/apis/notice/service.ts +++ b/src/apis/notice/service.ts @@ -52,9 +52,9 @@ export const getWhalebe = async (): Promise => { if (err) notificationToSlack('웨일비 조회 실패'); const whalebeData = res as WhalebeData[]; const today = new Date(); - const todayString = `${today.getFullYear()}-${String( + const todayString = `${today.getFullYear()}.${String( today.getMonth() + 1, - ).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`; + ).padStart(2, '0')}.${String(today.getDate()).padStart(2, '0')}`; const filteredData = whalebeData .filter((data) => data.date >= todayString) @@ -63,3 +63,18 @@ export const getWhalebe = async (): Promise => { }); }); }; + +export const getLanguage = async (): Promise => { + const query = `SELECT * FROM 어학공지 ORDER BY STR_TO_DATE(uploadDate, '%Y-%m-%d') DESC;`; + return new Promise((resolve) => { + db.query(query, (err, res) => { + if (err) { + notificationToSlack('어학 공지 응답 실패'); + resolve([]); + return; + } + const languageNoti = res as Notice[]; + resolve(languageNoti); + }); + }); +}; diff --git a/src/config/crawlingURL.ts b/src/config/crawlingURL.ts new file mode 100644 index 00000000..e85a1280 --- /dev/null +++ b/src/config/crawlingURL.ts @@ -0,0 +1,6 @@ +export const PKNU_URL = { + LANGUAGE_NOTICE_EXCHANGE_STUDENT: + 'https://www.pknu.ac.kr/main/163?pageIndex=1&bbsId=2&searchCondition=title&searchKeyword=교환학생&cd=', + LANGUAGE_NOTICE_LANGUAGE_TRANING: + 'https://www.pknu.ac.kr/main/163?pageIndex=1&bbsId=2&searchCondition=title&searchKeyword=어학연수&cd=', +}; diff --git a/src/crawling/noticeCrawling.ts b/src/crawling/noticeCrawling.ts index 3850cd2e..49341ca8 100644 --- a/src/crawling/noticeCrawling.ts +++ b/src/crawling/noticeCrawling.ts @@ -50,6 +50,7 @@ export const noticeCrawling = async (college: College): Promise => { export const noticeListCrawling = async ( link: string, + inputHostLink?: string, ): Promise => { const response = await axios.get(link); const hostLink = @@ -77,7 +78,8 @@ export const noticeListCrawling = async ( const anchorElement = $(element).find('a'); let tmpLink = anchorElement.attr('href'); - if (tmpLink[0] === '?') tmpLink = link + tmpLink; + if (inputHostLink) tmpLink = inputHostLink + tmpLink; + else if (tmpLink[0] === '?') tmpLink = link + tmpLink; else if (tmpLink[0] === '/') tmpLink = hostLink + tmpLink; const findDate = $(element) diff --git a/src/db/data/handler.ts b/src/db/data/handler.ts index 17b9ca6f..e69de29b 100644 --- a/src/db/data/handler.ts +++ b/src/db/data/handler.ts @@ -1,237 +0,0 @@ -import { - noticeContentCrawling, - noticeCrawling, - noticeListCrawling, -} from '@crawling/noticeCrawling'; -import { whalebeCrawling } from '@crawling/whalebeCrawling'; -import { RowDataPacket } from 'mysql2'; -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 => { - const saveCollegePromises = college.map((data) => { - const saveCollegeQuery = `INSERT INTO departments (collegeName, departmentName, departmentSubName, departmentLink) VALUES ('${data.collegeName}', '${data.departmentName}', '${data.departmentSubName}', '${data.departmentLink}');`; - return new Promise((resolve) => { - db.query(saveCollegeQuery, async (error) => { - if (error) { - await notificationToSlack(`DB에 학과 삽입 실패`); - resolve(); - return; - } - console.log('단과대 입력 성공!'); - resolve(); - }); - }); - }); - - await Promise.all(saveCollegePromises); -}; - -const saveNotice = (notice: Notice, major: string): Promise => { - const saveNoticeQuery = - 'INSERT INTO ' + major + ' (title, link, uploadDate) VALUES (?, ?, ?)'; - const values = [notice.title, notice.path, notice.date]; - - return new Promise((resolve) => { - db.query(saveNoticeQuery, values, (err) => { - if (err) { - console.log(`${major} 공지사항 입력 실패`); - resolve(); - return; - } - console.log(`${major} 공지사항 입력 성공`); - resolve(); - }); - }); -}; - -export const saveNoticeToDB = async (): Promise => { - const selectQuery = 'SELECT * FROM departments;'; - const results = await new Promise((resolve) => { - db.query(selectQuery, (error, results) => { - if (error) { - notificationToSlack(selectQuery + '실패'); - resolve([]); - return; - } - resolve(results as College[]); - }); - }); - - const savePromises: Promise[] = []; - const newNoticeMajor: PushNoti = {}; - - for (const row of results) { - const college: College = { - collegeName: row.collegeName, - departmentName: row.departmentName, - departmentSubName: row.departmentSubName, - departmentLink: row.departmentLink, - }; - - const noticeLink = await noticeCrawling(college); - const noticeLists = await noticeListCrawling(noticeLink); - if ( - noticeLists.normalNotice.length === 0 && - noticeLists.pinnedNotice.length === 0 - ) { - notificationToSlack(`${noticeLink} 크롤링 실패`); - continue; - } - - const major = - college.departmentSubName === '-' - ? college.departmentName - : college.departmentSubName; - - if (noticeLists.pinnedNotice !== undefined) { - const pinnedNotiQuery = `SELECT link FROM ${major}고정;`; - db.query(pinnedNotiQuery, async (err, res) => { - if (err) { - await notificationToSlack(pinnedNotiQuery.split('ORDER')[0] + '에러'); - return; - } - const rows = res as RowDataPacket[]; - let pinnedNotiLink: string[] = []; - - if (Array.isArray(rows) && rows.length > 0) - pinnedNotiLink = rows.map((row) => row.link); - - for (const notice of noticeLists.pinnedNotice) { - const result = await noticeContentCrawling(notice); - if (result.path === '') { - notificationToSlack(`${notice} 콘텐츠 크롤링 실패`); - continue; - } - if (!pinnedNotiLink.includes(result.path)) { - savePromises.push(saveNotice(result, major + '고정')); - } - } - }); - } - - const normalNotiQuery = `SELECT link FROM ${major}일반;`; - db.query(normalNotiQuery, async (err, res) => { - if (err) { - await notificationToSlack(normalNotiQuery.split('ORDER')[0] + '에러'); - return; - } - - const rows = res as RowDataPacket[]; - let normalNotiLink: string[] = []; - if (Array.isArray(rows) && rows.length > 0) - normalNotiLink = rows.map((row) => row.link); - - for (const notice of noticeLists.normalNotice) { - const result = await noticeContentCrawling(notice); - if (result.path === '') { - notificationToSlack(`${notice} 콘텐츠 크롤링 실패`); - continue; - } - - if (!normalNotiLink.includes(result.path)) { - if (!newNoticeMajor[major]) newNoticeMajor[major] = []; - - newNoticeMajor[major].push(result.title); - savePromises.push(saveNotice(result, major + '일반')); - } - } - }); - } - - await Promise.all(savePromises); - return newNoticeMajor; -}; - -const saveSchoolNotice = async ( - notices: string[], - mode: string, -): Promise[]> => { - const query = `SELECT link FROM 학교${mode} ORDER BY STR_TO_DATE(uploadDate, '%Y-%m-%d') DESC LIMIT 1;`; - const res = await new Promise((resolve) => { - db.query(query, async (err, res) => { - if (err) { - await notificationToSlack(query.split('ORDER')[0]); - resolve(''); - return; - } - const rows = res as RowDataPacket[]; - if (Array.isArray(rows) && rows.length > 0) { - const link = rows[0].link; - resolve(link); - } - resolve(''); - }); - }); - - const saveNoticeQuery = `INSERT INTO 학교${mode} (title, link, uploadDate) VALUES (?, ?, ?);`; - const savePromises: Promise[] = []; - - for (const list of notices) { - const notice = await noticeContentCrawling(list); - if (notice.path === '') { - notificationToSlack(`${notice} 콘텐츠 크롤링 실패`); - continue; - } - if (res === notice.path) break; - - savePromises.push( - new Promise((resolve) => { - const values = [notice.title, notice.path, notice.date]; - db.query(saveNoticeQuery, values, async (error) => { - if (error) { - console.log('학교 공지사항 입력 실패!'); - resolve(); - return; - } - console.log('학교 공지사항 입력 성공!'); - resolve(); - }); - }), - ); - } - - return savePromises; -}; - -export const saveSchoolNoticeToDB = async (): Promise => { - const savePromises: Promise[] = []; - const pknuNoticeLink = 'https://www.pknu.ac.kr/main/163'; - const noticeLists = await noticeListCrawling(pknuNoticeLink); - if (noticeLists.pinnedNotice !== undefined) { - const pinnedNoticePromises = await saveSchoolNotice( - noticeLists.pinnedNotice, - '고정', - ); - savePromises.push(...pinnedNoticePromises); - } - const normalNoticePromises = await saveSchoolNotice( - noticeLists.normalNotice, - '일반', - ); - savePromises.push(...normalNoticePromises); - - await Promise.all(savePromises); -}; - -export const saveWhalebeToDB = async (): Promise => { - const query = 'INSERT INTO 웨일비 (title, date, imgUrl) VALUES (?, ?, ?)'; - const whalebeDatas = await whalebeCrawling(); - - const promises = whalebeDatas.map((data) => { - const values = [data.title, data.date, data.imgUrl]; - - return new Promise((resolve) => { - db.query(query, values, () => { - resolve(); - }); - }); - }); - - Promise.all(promises); -}; diff --git a/src/db/data/languageHandler.ts b/src/db/data/languageHandler.ts new file mode 100644 index 00000000..d2ab192d --- /dev/null +++ b/src/db/data/languageHandler.ts @@ -0,0 +1,74 @@ +import { + noticeContentCrawling, + noticeListCrawling, +} from '@crawling/noticeCrawling'; +import db from '@db/index'; +import { RowDataPacket } from 'mysql2'; +import { Notice } from 'src/@types/college'; +import { PKNU_URL } from 'src/config/crawlingURL'; +import notificationToSlack from 'src/hooks/notificateToSlack'; + +const saveNotice = (notice: Notice): Promise => { + const query = 'INSERT INTO 어학공지 (title, link, uploadDate) VALUES (?,?,?)'; + const values = [notice.title, notice.path, notice.date]; + + return new Promise((resolve) => { + db.query(query, values, (err) => { + if (err) { + console.log('어학 공지사항 입력 실패'); + resolve(); + return; + } + console.log('어학 공지사항 입력 성공'); + resolve(); + }); + }); +}; + +export const saveLanguageNoticeToDB = async () => { + const languageNotiLists1 = await noticeListCrawling( + PKNU_URL.LANGUAGE_NOTICE_EXCHANGE_STUDENT, + 'https://www.pknu.ac.kr/main/163', + ); + const languageNotiLists2 = await noticeListCrawling( + PKNU_URL.LANGUAGE_NOTICE_LANGUAGE_TRANING, + 'https://www.pknu.ac.kr/main/163', + ); + + const lists = [ + ...languageNotiLists1.normalNotice, + ...languageNotiLists2.normalNotice, + ]; + + const savePromises: Promise[] = []; + const newNoticeTitle: string[] = []; + + const showDBQuery = `SELECT link FROM 어학공지;`; + db.query(showDBQuery, async (err, res) => { + if (err) { + await notificationToSlack('어학공지 조회 실패'); + return; + } + const rows = res as RowDataPacket[]; + let languageNoti: string[] = []; + + if (Array.isArray(rows) && rows.length > 0) + languageNoti = rows.map((row) => row.link); + + for (const notice of lists) { + const result = await noticeContentCrawling(notice); + if (result.path === '') { + notificationToSlack(`${notice} 어학 콘텐츠 크롤링 실패`); + continue; + } + + if (!languageNoti.includes(result.path)) { + savePromises.push(saveNotice(result)); + newNoticeTitle.push(result.title); + } + } + + await Promise.all(savePromises); + return newNoticeTitle; + }); +}; diff --git a/src/db/data/noticeHandler.ts b/src/db/data/noticeHandler.ts new file mode 100644 index 00000000..67155968 --- /dev/null +++ b/src/db/data/noticeHandler.ts @@ -0,0 +1,232 @@ +import { + noticeContentCrawling, + noticeCrawling, + noticeListCrawling, +} from '@crawling/noticeCrawling'; +import { whalebeCrawling } from '@crawling/whalebeCrawling'; +import { RowDataPacket } from 'mysql2'; +import { College, Notice } from 'src/@types/college'; +import db from 'src/db'; +import notificationToSlack from 'src/hooks/notificateToSlack'; + +export const saveDepartmentToDB = async (college: College[]): Promise => { + const saveCollegePromises = college.map((data) => { + const saveCollegeQuery = `INSERT INTO departments (collegeName, departmentName, departmentSubName, departmentLink) VALUES ('${data.collegeName}', '${data.departmentName}', '${data.departmentSubName}', '${data.departmentLink}');`; + return new Promise((resolve) => { + db.query(saveCollegeQuery, async (error) => { + if (error) { + await notificationToSlack(`DB에 학과 삽입 실패`); + resolve(); + return; + } + console.log('단과대 입력 성공!'); + resolve(); + }); + }); + }); + + await Promise.all(saveCollegePromises); +}; + +const saveNotice = (notice: Notice, major: string): Promise => { + const saveNoticeQuery = + 'INSERT INTO ' + major + ' (title, link, uploadDate) VALUES (?, ?, ?)'; + const values = [notice.title, notice.path, notice.date]; + + return new Promise((resolve) => { + db.query(saveNoticeQuery, values, (err) => { + if (err) { + console.log(`${major} 공지사항 입력 실패`); + resolve(); + return; + } + console.log(`${major} 공지사항 입력 성공`); + resolve(); + }); + }); +}; + +export const saveNoticeToDB = async (): Promise => { + const selectQuery = 'SELECT * FROM departments;'; + const results = await new Promise((resolve) => { + db.query(selectQuery, (error, results) => { + if (error) { + notificationToSlack(selectQuery + '실패'); + resolve([]); + return; + } + resolve(results as College[]); + }); + }); + + const savePromises: Promise[] = []; + const newNoticeMajor: string[] = []; + + for (const row of results) { + const college: College = { + collegeName: row.collegeName, + departmentName: row.departmentName, + departmentSubName: row.departmentSubName, + departmentLink: row.departmentLink, + }; + + const noticeLink = await noticeCrawling(college); + const noticeLists = await noticeListCrawling(noticeLink); + if ( + noticeLists.normalNotice.length === 0 && + noticeLists.pinnedNotice.length === 0 + ) { + notificationToSlack(`${noticeLink} 크롤링 실패`); + continue; + } + + const major = + college.departmentSubName === '-' + ? college.departmentName + : college.departmentSubName; + + if (noticeLists.pinnedNotice !== undefined) { + const pinnedNotiQuery = `SELECT link FROM ${major}고정;`; + db.query(pinnedNotiQuery, async (err, res) => { + if (err) { + await notificationToSlack(pinnedNotiQuery.split('ORDER')[0] + '에러'); + return; + } + const rows = res as RowDataPacket[]; + let pinnedNotiLink: string[] = []; + + if (Array.isArray(rows) && rows.length > 0) + pinnedNotiLink = rows.map((row) => row.link); + + for (const notice of noticeLists.pinnedNotice) { + const result = await noticeContentCrawling(notice); + if (result.path === '') { + notificationToSlack(`${notice} 콘텐츠 크롤링 실패`); + continue; + } + if (!pinnedNotiLink.includes(result.path)) { + if (!newNoticeMajor.includes(major)) newNoticeMajor.push(major); + savePromises.push(saveNotice(result, major + '고정')); + } + } + }); + } + + const normalNotiQuery = `SELECT link FROM ${major}일반;`; + db.query(normalNotiQuery, async (err, res) => { + if (err) { + await notificationToSlack(normalNotiQuery.split('ORDER')[0] + '에러'); + return; + } + + const rows = res as RowDataPacket[]; + let normalNotiLink: string[] = []; + if (Array.isArray(rows) && rows.length > 0) + normalNotiLink = rows.map((row) => row.link); + + for (const notice of noticeLists.normalNotice) { + const result = await noticeContentCrawling(notice); + if (result.path === '') { + notificationToSlack(`${notice} 콘텐츠 크롤링 실패`); + continue; + } + + if (!normalNotiLink.includes(result.path)) { + if (!newNoticeMajor.includes(major)) newNoticeMajor.push(major); + savePromises.push(saveNotice(result, major + '일반')); + } + } + }); + } + + await Promise.all(savePromises); + return newNoticeMajor; +}; + +const saveSchoolNotice = async ( + notices: string[], + mode: string, +): Promise[]> => { + const query = `SELECT link FROM 학교${mode} ORDER BY STR_TO_DATE(uploadDate, '%Y-%m-%d') DESC LIMIT 1;`; + const res = await new Promise((resolve) => { + db.query(query, async (err, res) => { + if (err) { + await notificationToSlack(query.split('ORDER')[0]); + resolve(''); + return; + } + const rows = res as RowDataPacket[]; + if (Array.isArray(rows) && rows.length > 0) { + const link = rows[0].link; + resolve(link); + } + resolve(''); + }); + }); + + const saveNoticeQuery = `INSERT INTO 학교${mode} (title, link, uploadDate) VALUES (?, ?, ?);`; + const savePromises: Promise[] = []; + + for (const list of notices) { + const notice = await noticeContentCrawling(list); + if (notice.path === '') { + notificationToSlack(`${notice} 콘텐츠 크롤링 실패`); + continue; + } + if (res === notice.path) break; + + savePromises.push( + new Promise((resolve) => { + const values = [notice.title, notice.path, notice.date]; + db.query(saveNoticeQuery, values, async (error) => { + if (error) { + console.log('학교 공지사항 입력 실패!'); + resolve(); + return; + } + console.log('학교 공지사항 입력 성공!'); + resolve(); + }); + }), + ); + } + + return savePromises; +}; + +export const saveSchoolNoticeToDB = async (): Promise => { + const savePromises: Promise[] = []; + const pknuNoticeLink = 'https://www.pknu.ac.kr/main/163'; + const noticeLists = await noticeListCrawling(pknuNoticeLink); + if (noticeLists.pinnedNotice !== undefined) { + const pinnedNoticePromises = await saveSchoolNotice( + noticeLists.pinnedNotice, + '고정', + ); + savePromises.push(...pinnedNoticePromises); + } + const normalNoticePromises = await saveSchoolNotice( + noticeLists.normalNotice, + '일반', + ); + savePromises.push(...normalNoticePromises); + + await Promise.all(savePromises); +}; + +export const saveWhalebeToDB = async (): Promise => { + const query = 'INSERT INTO 웨일비 (title, date, imgUrl) VALUES (?, ?, ?)'; + const whalebeDatas = await whalebeCrawling(); + + const promises = whalebeDatas.map((data) => { + const values = [data.title, data.date, data.imgUrl]; + + return new Promise((resolve) => { + db.query(query, values, () => { + resolve(); + }); + }); + }); + + Promise.all(promises); +}; diff --git a/src/db/table/createTables.ts b/src/db/table/createTables.ts index 845517a9..7a010496 100644 --- a/src/db/table/createTables.ts +++ b/src/db/table/createTables.ts @@ -119,9 +119,27 @@ const createWhalebeDataTable = () => { }); }; +const createLanguageDataTable = () => { + const createTableQuery = `CREATE TABLE 어학공지 ( + id INT PRIMARY KEY AUTO_INCREMENT, + title VARCHAR(255) NOT NULL, + link VARCHAR(255) NOT NULL UNIQUE, + uploadDate VARCHAR(255) NOT NULL + );`; + + db.query(createTableQuery, (error) => { + if (error) { + console.log('어학 DB 생성 실패', error); + return; + } + console.log('어학 테이블 생성 성공!'); + }); +}; + const createAllTables = (college: College[]) => { createDepartmentTable(); createWhalebeDataTable(); + createLanguageDataTable(); createGraduationTable(); createSchoolNoticeTable(); createNoticeTable(college); diff --git a/src/hooks/cronNoticeCrawling.ts b/src/hooks/cronNoticeCrawling.ts index 0c3a0595..05e6a174 100644 --- a/src/hooks/cronNoticeCrawling.ts +++ b/src/hooks/cronNoticeCrawling.ts @@ -1,10 +1,11 @@ import { pushNotification } from '@apis/subscribe/service'; +import { saveLanguageNoticeToDB } from '@db/data/languageHandler'; import { PushNoti, saveNoticeToDB, saveSchoolNoticeToDB, saveWhalebeToDB, -} from '@db/data/handler'; +} from '@db/data/noticeHandler'; import cron from 'node-cron'; import notificationToSlack from 'src/hooks/notificateToSlack'; @@ -20,6 +21,7 @@ const pushToUsers = async (pushNotiToUserLists: PushNoti) => { cron.schedule('0 0-9 * * 1-5', async () => { const pushNotiToUserLists = await saveNoticeToDB(); await saveSchoolNoticeToDB(); + await saveLanguageNoticeToDB(); await saveWhalebeToDB(); const today = new Date(); const year = today.getFullYear(); diff --git a/src/hooks/startCrawlingData.ts b/src/hooks/startCrawlingData.ts index bdd8b500..01175fb8 100644 --- a/src/hooks/startCrawlingData.ts +++ b/src/hooks/startCrawlingData.ts @@ -1,11 +1,12 @@ import { collegeCrawling } from '@crawling/collegeCrawling'; import { saveGraduationRequirementToDB } from '@db/data/graduation'; +import { saveLanguageNoticeToDB } from '@db/data/languageHandler'; import { saveDepartmentToDB, saveNoticeToDB, saveSchoolNoticeToDB, saveWhalebeToDB, -} from '@db/data/handler'; +} from '@db/data/noticeHandler'; import db from '@db/index'; import createNoticeTable from '@db/table/createTables'; import { RowDataPacket } from 'mysql2'; @@ -21,6 +22,7 @@ export const initialCrawling = () => { const collegeList = await collegeCrawling(); createNoticeTable(collegeList); await saveDepartmentToDB(collegeList); + await saveLanguageNoticeToDB(); await saveGraduationRequirementToDB(); await saveSchoolNoticeToDB(); await saveWhalebeToDB(); diff --git a/src/index.ts b/src/index.ts index 8b27face..81bdce5f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ import noticeRouter from '@apis/notice/controller'; import subscriptionRouter from '@apis/subscribe/controller'; import suggestionRouter from '@apis/suggestion/controller'; import env from '@config'; -import { saveWhalebeToDB } from '@db/data/handler'; +import { saveLanguageNoticeToDB } from '@db/data/languageHandler'; import db from '@db/index'; import { corsOptions } from '@middlewares/cors'; import errorHandler from '@middlewares/error-handler'; @@ -42,26 +42,31 @@ app.listen(env.SERVER_PORT, () => { webpush(); -const forDeployedServer = () => { +const handleDeployToServer = () => { // 이 함수는 현재 배포되어있는 서버를 위해 사용되는 로직이며 최초 서버에 배포되는 1회만 실행되도록 하기위한 함수에요 // 그렇기에 아래에 작성된 코드들은 배포서버에 배포되면 다음 배포전 수정해주세요!! - // 웨일비 관련 테이블 생성 후 데이터 삽입 - const createTableQuery = `CREATE TABLE 웨일비 ( - id INT PRIMARY KEY AUTO_INCREMENT, - title VARCHAR(255) NOT NULL UNIQUE, - date VARCHAR(255) NOT NULL, - imgUrl VARCHAR(255) NOT NULL - );`; + // 어학 관련 테이블 생성 후 데이터 삽입 + const createLanguageDataTable = () => { + const createTableQuery = `CREATE TABLE 어학공지 ( + id INT PRIMARY KEY AUTO_INCREMENT, + title VARCHAR(255) NOT NULL, + link VARCHAR(255) NOT NULL UNIQUE, + uploadDate VARCHAR(255) NOT NULL + );`; - db.query(createTableQuery, (error) => { - if (error) { - console.log('웨일비 DB 생성 실패', error); - return; - } - console.log('웨일비 테이블 생성 성공!'); - }); + db.query(createTableQuery, async (error) => { + if (error) { + console.log('어학 DB 생성 실패', error); + return; + } + + console.log('어학 테이블 생성 성공!'); + await saveLanguageNoticeToDB(); + }); + }; + + createLanguageDataTable(); }; -// saveWhalebeToDB(); -// forDeployedServer(); +handleDeployToServer();