From 3c537af7b6920c2041aba162e9725bd15368c86a Mon Sep 17 00:00:00 2001 From: Starcea Date: Sat, 29 Apr 2023 16:10:23 +0900 Subject: [PATCH] feat: HisTimetable --- src/client.ts | 14 ++++++++++++++ src/http.ts | 12 ++++++++++++ src/types.ts | 28 +++++++++++++++++++++++++--- tests/constants.ts | 1 + tests/timetable.test.ts | 30 ++++++++++++++++++++++++++++-- 5 files changed, 80 insertions(+), 5 deletions(-) diff --git a/src/client.ts b/src/client.ts index bb2c51b..f4b1673 100644 --- a/src/client.ts +++ b/src/client.ts @@ -4,6 +4,8 @@ import type { AcaInsTiInfoResponse, ElsTimetableParam, ElsTimetableResponse, + HisTimetableParam, + HisTimetableResponse, MealServiceDietInfoParam, MealServiceDietInfoResponse, MisTimetableParam, @@ -85,4 +87,16 @@ export class Neis extends NeisRequest { ): Promise { return (await this.misTimetableRaw(params))[0] } + + async getHisTimetable( + params: HisTimetableParam + ): Promise { + return await this.hisTimetableRaw(params) + } + + async getHisTimetableOne( + params: HisTimetableParam + ): Promise { + return (await this.hisTimetableRaw(params))[0] + } } diff --git a/src/http.ts b/src/http.ts index 92a3de9..dc4a0b1 100644 --- a/src/http.ts +++ b/src/http.ts @@ -4,6 +4,8 @@ import type { AcaInsTiInfoResponse, ElsTimetableParam, ElsTimetableResponse, + HisTimetableParam, + HisTimetableResponse, MealServiceDietInfoParam, MealServiceDietInfoResponse, MisTimetableParam, @@ -125,6 +127,16 @@ export class NeisRequest { ) } + protected async hisTimetableRaw( + params: HisTimetableParam + ): Promise { + return await this.request( + 'GET', + 'hisTimetable', + params + ) + } + private async request( method: string, endpoint: string, diff --git a/src/types.ts b/src/types.ts index afb87b7..8bcc804 100644 --- a/src/types.ts +++ b/src/types.ts @@ -89,7 +89,7 @@ export interface AcaInsTiInfoParam extends DefaultParam { readonly LE_CRSE_NM?: string } -export interface ElsTimetableParam extends DefaultParam, RequiresSchoolParam { +interface BaseTimetableParam extends DefaultParam, RequiresSchoolParam { /** 학년도 */ readonly AY?: string /** 학기 */ @@ -100,19 +100,31 @@ export interface ElsTimetableParam extends DefaultParam, RequiresSchoolParam { readonly GRADE?: string /** 반명 */ readonly CLASS_NM?: string - /** 교시 */ - readonly PERIO?: string /** 시간표시작일자 */ readonly TI_FROM_YMD?: string /** 시간표종료일자 */ readonly TI_TO_YMD?: string } +export interface ElsTimetableParam extends BaseTimetableParam { + /** 교시 */ + readonly PERIO?: string +} + export interface MisTimetableParam extends ElsTimetableParam { /** 주야과정명 */ readonly DGHT_CRSE_SC_NM?: string } +export interface HisTimetableParam extends BaseTimetableParam { + /** 계열명 */ + readonly ORD_SC_NM?: string + /** 학과명 */ + readonly DDDEP_NM?: string + /** 강의실명 */ + readonly CLRM_NM?: string +} + export type Params = | SchoolInfoParam | MealServiceDietInfoParam @@ -120,6 +132,7 @@ export type Params = | AcaInsTiInfoParam | ElsTimetableParam | MisTimetableParam + | HisTimetableParam interface BaseSchoolResponse { /** 시도교육청코드 */ @@ -305,3 +318,12 @@ export interface MisTimetableResponse extends ElsTimetableResponse { /** 주야과정명 */ readonly DGHT_CRSE_SC_NM: string } + +export interface HisTimetableResponse extends MisTimetableResponse { + /** 계열명 */ + readonly ORD_SC_NM: string + /** 학과명 */ + readonly DDDEP_NM: string + /** 강의실명 */ + readonly CLRM_NM: string +} diff --git a/tests/constants.ts b/tests/constants.ts index 033f1a3..8e4f1a4 100644 --- a/tests/constants.ts +++ b/tests/constants.ts @@ -5,3 +5,4 @@ export const YMD = '20230428' export const ELS = '7091414' export const MIS = '7091455' +export const HIS = '7011169' diff --git a/tests/timetable.test.ts b/tests/timetable.test.ts index 69103ab..9e77cda 100644 --- a/tests/timetable.test.ts +++ b/tests/timetable.test.ts @@ -1,5 +1,9 @@ -import type { ElsTimetableResponse, MisTimetableResponse } from '../src' -import { AE, ELS, MIS, YMD } from './constants' +import type { + ElsTimetableResponse, + HisTimetableResponse, + MisTimetableResponse, +} from '../src' +import { AE, ELS, HIS, MIS, YMD } from './constants' import { neis } from './utils' describe('Timetable', () => { @@ -48,4 +52,26 @@ describe('Timetable', () => { expect(data).toMatchObject(data) }) + + it('should return HisTimetableResponse[]', async () => { + const data = await neis.getHisTimetable({ + ATPT_OFCDC_SC_CODE: AE, + SD_SCHUL_CODE: HIS, + ALL_TI_YMD: YMD, + }) + + expect(data).toMatchObject(data) + }) + + it('should return HisTimetableResponse', async () => { + const data = await neis.getHisTimetableOne({ + ATPT_OFCDC_SC_CODE: AE, + SD_SCHUL_CODE: HIS, + ALL_TI_YMD: YMD, + GRADE: '1', + CLASS_NM: '1', + }) + + expect(data).toMatchObject(data) + }) })