From b2f041adce1bf840c20f3465bcc4b6193aab37c4 Mon Sep 17 00:00:00 2001 From: Starcea Date: Wed, 5 Apr 2023 23:30:48 +0900 Subject: [PATCH] feat: SchoolSchedule --- src/http.ts | 11 +++++++++ src/structures/school.ts | 20 +++++++++++++++- src/types.ts | 49 +++++++++++++++++++++++++++++++++++++++- tests/schedule.test.ts | 31 +++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 tests/schedule.test.ts diff --git a/src/http.ts b/src/http.ts index 5df2102..32ff760 100644 --- a/src/http.ts +++ b/src/http.ts @@ -3,6 +3,8 @@ import type { MealRequestParam, NeisConfig, RequestParam, + ScheduleInfo, + ScheduleRequestParam, SchoolInfo, SchoolRequestParam, } from './types' @@ -113,4 +115,13 @@ export class NeisRequest { ): Promise { return await this.request('GET', 'mealServiceDietInfo', params) } + + async SchoolScheduleRaw( + params: ScheduleRequestParam & { + ATPT_OFCDC_SC_CODE: string + SD_SCHUL_CODE: string + } + ): Promise { + return await this.request('GET', 'SchoolSchedule', params) + } } diff --git a/src/structures/school.ts b/src/structures/school.ts index 69cf8df..2c008cf 100644 --- a/src/structures/school.ts +++ b/src/structures/school.ts @@ -1,5 +1,11 @@ import type { NeisRequest } from '../http' -import type { MealInfo, MealRequestParam, SchoolInfo } from '../types' +import type { + MealInfo, + MealRequestParam, + ScheduleInfo, + ScheduleRequestParam, + SchoolInfo, +} from '../types' /** 학교 정보를 담는 클래스입니다. */ export class School implements SchoolInfo { @@ -72,4 +78,16 @@ export class School implements SchoolInfo { async getMealOne(params: MealRequestParam): Promise { return await this.getMeal(params).then((data) => data[0]) } + + async getSchedule(params: ScheduleRequestParam): Promise { + return await this.#neis.SchoolScheduleRaw({ + ATPT_OFCDC_SC_CODE: this.ATPT_OFCDC_SC_CODE, + SD_SCHUL_CODE: this.SD_SCHUL_CODE, + ...params, + }) + } + + async getScheduleOne(params: ScheduleRequestParam): Promise { + return await this.getSchedule(params).then((data) => data[0]) + } } diff --git a/src/types.ts b/src/types.ts index ba2653f..1bc3ae3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -39,7 +39,23 @@ export interface MealRequestParam { readonly MLSV_TO_YMD?: string } -export type RequestParam = SchoolRequestParam | MealRequestParam +export interface ScheduleRequestParam { + /** 주야과정명 */ + readonly DGHT_CRSE_SC_NM?: string + /** 학교과정명 */ + readonly SCHUL_CRSE_SC_NM?: string + /** 학사일자 */ + readonly AY_YMD?: string + /** 학사시작일자 */ + readonly AY_FROM_YMD?: string + /** 학사종료일자 */ + readonly AY_TO_YMD?: string +} + +export type RequestParam = + | SchoolRequestParam + | MealRequestParam + | ScheduleRequestParam interface BaseInfo { /** 시도교육청코드 */ @@ -119,3 +135,34 @@ export interface MealInfo extends BaseInfo { /** 급식종료일자 */ readonly MLSV_TO_YMD: string } + +export interface ScheduleInfo extends BaseInfo { + /** 학년도 */ + readonly AY: string + /** 주야과정명 */ + readonly DGHT_CRSE_SC_NM: string | null + /** 학교과정명 */ + readonly SCHUL_CRSE_SC_NM: string + /** 수업공제일명 */ + readonly SBTR_DD_SC_NM: string + /** 학사일자 */ + readonly AA_YMD: string + /** 행사명 */ + readonly EVENT_NM: string + /** 행사내용 */ + readonly EVENT_CNTNT: string + /** 1학년행사여부 */ + readonly ONE_GRADE_EVENT_YN: string + /** 2학년행사여부 */ + readonly TWO_GRADE_EVENT_YN: string + /** 3학년행사여부 */ + readonly THREE_GRADE_EVENT_YN: string + /** 4학년행사여부 */ + readonly FOUR_GRADE_EVENT_YN: string + /** 5학년행사여부 */ + readonly FIVE_GRADE_EVENT_YN: string + /** 6학년행사여부 */ + readonly SIX_GRADE_EVENT_YN: string + /** 수정일 */ + readonly LOAD_DTM: string +} diff --git a/tests/schedule.test.ts b/tests/schedule.test.ts new file mode 100644 index 0000000..c0bf43f --- /dev/null +++ b/tests/schedule.test.ts @@ -0,0 +1,31 @@ +import { logger, neis } from '.' +import type { ScheduleInfo } from '../src/types' + +describe('Schedule', () => { + it('should return ScheduleInfo[]', async () => { + const schools = await neis.getSchool({ + ATPT_OFCDC_SC_CODE: 'B10', + }) + + const data: ScheduleInfo[] = [] + for await (const school of schools) { + data.push(await school.getScheduleOne({ AY_YMD: '20230301' })) + } + + logger.info(data) + + expect(data).toMatchObject(data) + }) + + it('should return ScheduleInfo', async () => { + const school = await neis.getSchoolOne({ + ATPT_OFCDC_SC_CODE: 'B10', + SD_SCHUL_CODE: '7091455', + }) + + const data = await school.getScheduleOne({ AY_YMD: '20230301' }) + logger.info(data) + + expect(data).toMatchObject(data) + }) +})