Skip to content

Commit

Permalink
feat: SpsTimetable
Browse files Browse the repository at this point in the history
  • Loading branch information
star0202 committed Apr 29, 2023
1 parent 3c537af commit 6262603
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import type {
SchoolInfoResponse,
SchoolScheduleParam,
SchoolScheduleResponse,
SpsTimetableParam,
SpsTimetableResponse,
} from './types'

export class Neis extends NeisRequest {
Expand Down Expand Up @@ -99,4 +101,16 @@ export class Neis extends NeisRequest {
): Promise<HisTimetableResponse> {
return (await this.hisTimetableRaw(params))[0]
}

async getSpsTimetable(
params: SpsTimetableParam
): Promise<SpsTimetableResponse[]> {
return await this.spsTimetableRaw(params)
}

async getSpsTimetableOne(
params: SpsTimetableParam
): Promise<SpsTimetableResponse> {
return (await this.spsTimetableRaw(params))[0]
}
}
12 changes: 12 additions & 0 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import type {
SchoolInfoResponse,
SchoolScheduleParam,
SchoolScheduleResponse,
SpsTimetableParam,
SpsTimetableResponse,
} from './types'
import type { AxiosInstance, AxiosRequestConfig } from 'axios'
import axios from 'axios'
Expand Down Expand Up @@ -137,6 +139,16 @@ export class NeisRequest {
)
}

protected async spsTimetableRaw(
params: SpsTimetableParam
): Promise<SpsTimetableResponse[]> {
return await this.request<SpsTimetableResponse>(
'GET',
'spsTimetable',
params
)
}

private async request<T>(
method: string,
endpoint: string,
Expand Down
15 changes: 15 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ export interface HisTimetableParam extends BaseTimetableParam {
readonly CLRM_NM?: string
}

export interface SpsTimetableParam extends ElsTimetableParam {
/** 학교과정명 */
readonly SCHUL_CRSE_SC_NM?: string
/** 강의실명 */
readonly CLRM_NM?: string
}

export type Params =
| SchoolInfoParam
| MealServiceDietInfoParam
Expand All @@ -133,6 +140,7 @@ export type Params =
| ElsTimetableParam
| MisTimetableParam
| HisTimetableParam
| SpsTimetableParam

interface BaseSchoolResponse {
/** 시도교육청코드 */
Expand Down Expand Up @@ -327,3 +335,10 @@ export interface HisTimetableResponse extends MisTimetableResponse {
/** 강의실명 */
readonly CLRM_NM: string
}

export interface SpsTimetableResponse extends ElsTimetableResponse {
/** 학교과정명 */
readonly SCHUL_CRSE_SC_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 @@ -6,3 +6,4 @@ export const YMD = '20230428'
export const ELS = '7091414'
export const MIS = '7091455'
export const HIS = '7011169'
export const SPS = '7010459'
26 changes: 25 additions & 1 deletion tests/timetable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import type {
ElsTimetableResponse,
HisTimetableResponse,
MisTimetableResponse,
SpsTimetableResponse,
} from '../src'
import { AE, ELS, HIS, MIS, YMD } from './constants'
import { AE, ELS, HIS, MIS, SPS, YMD } from './constants'
import { neis } from './utils'

describe('Timetable', () => {
Expand Down Expand Up @@ -74,4 +75,27 @@ describe('Timetable', () => {

expect(data).toMatchObject<HisTimetableResponse>(data)
})

it('should return SpsTimetableResponse[]', async () => {
const data = await neis.getSpsTimetable({
ATPT_OFCDC_SC_CODE: AE,
SD_SCHUL_CODE: SPS,
ALL_TI_YMD: YMD,
})

expect(data).toMatchObject<SpsTimetableResponse[]>(data)
})

it('should return SpsTimetableResponse', async () => {
const data = await neis.getSpsTimetableOne({
ATPT_OFCDC_SC_CODE: AE,
SD_SCHUL_CODE: SPS,
ALL_TI_YMD: YMD,
GRADE: '1',
CLASS_NM: '1',
PERIO: '1',
})

expect(data).toMatchObject<SpsTimetableResponse>(data)
})
})

0 comments on commit 6262603

Please sign in to comment.