Skip to content

Commit

Permalink
feat: HisTimetable
Browse files Browse the repository at this point in the history
  • Loading branch information
star0202 committed Apr 29, 2023
1 parent fc87cd7 commit 3c537af
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
14 changes: 14 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type {
AcaInsTiInfoResponse,
ElsTimetableParam,
ElsTimetableResponse,
HisTimetableParam,
HisTimetableResponse,
MealServiceDietInfoParam,
MealServiceDietInfoResponse,
MisTimetableParam,
Expand Down Expand Up @@ -85,4 +87,16 @@ export class Neis extends NeisRequest {
): Promise<MisTimetableResponse> {
return (await this.misTimetableRaw(params))[0]
}

async getHisTimetable(
params: HisTimetableParam
): Promise<HisTimetableResponse[]> {
return await this.hisTimetableRaw(params)
}

async getHisTimetableOne(
params: HisTimetableParam
): Promise<HisTimetableResponse> {
return (await this.hisTimetableRaw(params))[0]
}
}
12 changes: 12 additions & 0 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type {
AcaInsTiInfoResponse,
ElsTimetableParam,
ElsTimetableResponse,
HisTimetableParam,
HisTimetableResponse,
MealServiceDietInfoParam,
MealServiceDietInfoResponse,
MisTimetableParam,
Expand Down Expand Up @@ -125,6 +127,16 @@ export class NeisRequest {
)
}

protected async hisTimetableRaw(
params: HisTimetableParam
): Promise<HisTimetableResponse[]> {
return await this.request<HisTimetableResponse>(
'GET',
'hisTimetable',
params
)
}

private async request<T>(
method: string,
endpoint: string,
Expand Down
28 changes: 25 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
/** 학기 */
Expand All @@ -100,26 +100,39 @@ 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
| SchoolScheduleParam
| AcaInsTiInfoParam
| ElsTimetableParam
| MisTimetableParam
| HisTimetableParam

interface BaseSchoolResponse {
/** 시도교육청코드 */
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const YMD = '20230428'

export const ELS = '7091414'
export const MIS = '7091455'
export const HIS = '7011169'
30 changes: 28 additions & 2 deletions tests/timetable.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -48,4 +52,26 @@ describe('Timetable', () => {

expect(data).toMatchObject<MisTimetableResponse>(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<HisTimetableResponse[]>(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<HisTimetableResponse>(data)
})
})

0 comments on commit 3c537af

Please sign in to comment.