diff --git a/src/client.ts b/src/client.ts index 8c9ae91..4fd927a 100644 --- a/src/client.ts +++ b/src/client.ts @@ -2,6 +2,8 @@ import { NeisRequest } from './http' import type { AcaInsTiInfoParam, AcaInsTiInfoResponse, + ElsTimetableParam, + ElsTimetableResponse, MealServiceDietInfoParam, MealServiceDietInfoResponse, NeisConfig, @@ -57,4 +59,16 @@ export class Neis extends NeisRequest { ): Promise { return (await this.acaInsTiInfoRaw(params))[0] } + + async getElsTimetable( + params: ElsTimetableParam + ): Promise { + return await this.elsTimetableRaw(params) + } + + async getElsTimetableOne( + params: ElsTimetableParam + ): Promise { + return (await this.elsTimetableRaw(params))[0] + } } diff --git a/src/http.ts b/src/http.ts index 0f5ecba..e8330e3 100644 --- a/src/http.ts +++ b/src/http.ts @@ -1,6 +1,8 @@ import type { AcaInsTiInfoParam, AcaInsTiInfoResponse, + ElsTimetableParam, + ElsTimetableResponse, MealServiceDietInfoParam, MealServiceDietInfoResponse, NeisConfig, @@ -100,6 +102,16 @@ export class NeisRequest { ) } + protected async elsTimetableRaw( + params: ElsTimetableParam + ): Promise { + return await this.request( + 'GET', + 'elsTimetable', + params + ) + } + private async request( method: string, endpoint: string, diff --git a/src/types.ts b/src/types.ts index 058b37a..18dc755 100644 --- a/src/types.ts +++ b/src/types.ts @@ -13,6 +13,13 @@ export interface NeisConfig { readonly logger?: Logger } +interface RequiresSchoolParam { + /** 시도교육청코드 */ + readonly ATPT_OFCDC_SC_CODE: string + /** 표준학교코드 */ + readonly SD_SCHUL_CODE: string +} + export interface SchoolInfoParam { /** 시도교육청코드 */ readonly ATPT_OFCDC_SC_CODE?: string @@ -28,11 +35,7 @@ export interface SchoolInfoParam { readonly FOND_SC_NM?: string } -export interface MealServiceDietInfoParam { - /** 시도교육청코드 */ - readonly ATPT_OFCDC_SC_CODE: string - /** 표준학교코드 */ - readonly SD_SCHUL_CODE: string +export interface MealServiceDietInfoParam extends RequiresSchoolParam { /** 식사코드 */ readonly MMEAL_SC_CODE?: string /** 급식일자 */ @@ -43,11 +46,7 @@ export interface MealServiceDietInfoParam { readonly MLSV_TO_YMD?: string } -export interface SchoolScheduleParam { - /** 시도교육청코드 */ - readonly ATPT_OFCDC_SC_CODE: string - /** 표준학교코드 */ - readonly SD_SCHUL_CODE: string +export interface SchoolScheduleParam extends RequiresSchoolParam { /** 주야과정명 */ readonly DGHT_CRSE_SC_NM?: string /** 학교과정명 */ @@ -77,13 +76,33 @@ export interface AcaInsTiInfoParam { readonly LE_CRSE_NM?: string } +export interface ElsTimetableParam extends RequiresSchoolParam { + /** 학년도 */ + readonly AY?: string + /** 학기 */ + readonly SEM?: string + /** 시간표일자 */ + readonly ALL_TI_YMD?: string + /** 학년 */ + readonly GRADE?: string + /** 반명 */ + readonly CLASS_NM?: string + /** 교시 */ + readonly PERIO?: string + /** 시간표시작일자 */ + readonly TI_FROM_YMD?: string + /** 시간표종료일자 */ + readonly TI_TO_YMD?: string +} + export type Params = | SchoolInfoParam | MealServiceDietInfoParam | SchoolScheduleParam | AcaInsTiInfoParam + | ElsTimetableParam -interface SchoolBaseResponse { +interface BaseSchoolResponse { /** 시도교육청코드 */ readonly ATPT_OFCDC_SC_CODE: string /** 시도교육청명 */ @@ -94,7 +113,7 @@ interface SchoolBaseResponse { readonly SCHUL_NM: string } -export interface SchoolInfoResponse extends SchoolBaseResponse { +export interface SchoolInfoResponse extends BaseSchoolResponse { /** 영문학교명 */ readonly ENG_SCHUL_NM: string /** 학교종류명 */ @@ -139,7 +158,7 @@ export interface SchoolInfoResponse extends SchoolBaseResponse { readonly LOAD_DTM: string } -export interface MealServiceDietInfoResponse extends SchoolBaseResponse { +export interface MealServiceDietInfoResponse extends BaseSchoolResponse { /** 식사코드 */ readonly MMEAL_SC_CODE: string /** 식사명 */ @@ -162,7 +181,7 @@ export interface MealServiceDietInfoResponse extends SchoolBaseResponse { readonly MLSV_TO_YMD: string } -export interface SchoolScheduleResponse extends SchoolBaseResponse { +export interface SchoolScheduleResponse extends BaseSchoolResponse { /** 학년도 */ readonly AY: string /** 주야과정명 */ @@ -243,3 +262,22 @@ export interface AcaInsTiInfoResponse { /** 수정일 */ readonly LOAD_DTM: string } + +export interface ElsTimetableResponse extends BaseSchoolResponse { + /** 학년도 */ + readonly AY: string + /** 학기 */ + readonly SEM: string + /** 시간표일자 */ + readonly ALL_TI_YMD: string + /** 학년 */ + readonly GRADE: string + /** 반명 */ + readonly CLASS_NM: string + /** 교시 */ + readonly PERIO: string + /** 수업내용 */ + readonly ITRT_CNTNT: string + /** 수정일 */ + readonly LOAD_DTM: string +} diff --git a/tests/constants.ts b/tests/constants.ts index 424bd55..da8c880 100644 --- a/tests/constants.ts +++ b/tests/constants.ts @@ -2,3 +2,5 @@ export const AE = 'B10' export const AN = '3000037367' export const SE = '7010057' export const YMD = '20230302' + +export const ELS = '7091414' diff --git a/tests/timetable.test.ts b/tests/timetable.test.ts new file mode 100644 index 0000000..1a4c9fd --- /dev/null +++ b/tests/timetable.test.ts @@ -0,0 +1,28 @@ +import type { ElsTimetableResponse } from '../src' +import { AE, ELS, YMD } from './constants' +import { neis } from './utils' + +describe('Timetable', () => { + it('should return ElsTimetableResponse[]', async () => { + const data = await neis.getElsTimetable({ + ATPT_OFCDC_SC_CODE: AE, + SD_SCHUL_CODE: ELS, + ALL_TI_YMD: YMD, + }) + + expect(data).toMatchObject(data) + }) + + it('should return ElsTimetableResponse', async () => { + const data = await neis.getElsTimetableOne({ + ATPT_OFCDC_SC_CODE: AE, + SD_SCHUL_CODE: ELS, + ALL_TI_YMD: YMD, + GRADE: '1', + CLASS_NM: '1', + PERIO: '1', + }) + + expect(data).toMatchObject(data) + }) +})