Skip to content

Commit

Permalink
feat: ElsTimetable
Browse files Browse the repository at this point in the history
  • Loading branch information
star0202 committed Apr 29, 2023
1 parent 287f273 commit 4067d2e
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 14 deletions.
14 changes: 14 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { NeisRequest } from './http'
import type {
AcaInsTiInfoParam,
AcaInsTiInfoResponse,
ElsTimetableParam,
ElsTimetableResponse,
MealServiceDietInfoParam,
MealServiceDietInfoResponse,
NeisConfig,
Expand Down Expand Up @@ -57,4 +59,16 @@ export class Neis extends NeisRequest {
): Promise<AcaInsTiInfoResponse> {
return (await this.acaInsTiInfoRaw(params))[0]
}

async getElsTimetable(
params: ElsTimetableParam
): Promise<ElsTimetableResponse[]> {
return await this.elsTimetableRaw(params)
}

async getElsTimetableOne(
params: ElsTimetableParam
): Promise<ElsTimetableResponse> {
return (await this.elsTimetableRaw(params))[0]
}
}
12 changes: 12 additions & 0 deletions src/http.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type {
AcaInsTiInfoParam,
AcaInsTiInfoResponse,
ElsTimetableParam,
ElsTimetableResponse,
MealServiceDietInfoParam,
MealServiceDietInfoResponse,
NeisConfig,
Expand Down Expand Up @@ -100,6 +102,16 @@ export class NeisRequest {
)
}

protected async elsTimetableRaw(
params: ElsTimetableParam
): Promise<ElsTimetableResponse[]> {
return await this.request<ElsTimetableResponse>(
'GET',
'elsTimetable',
params
)
}

private async request<T>(
method: string,
endpoint: string,
Expand Down
66 changes: 52 additions & 14 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ export interface NeisConfig {
readonly logger?: Logger<unknown>
}

interface RequiresSchoolParam {
/** 시도교육청코드 */
readonly ATPT_OFCDC_SC_CODE: string
/** 표준학교코드 */
readonly SD_SCHUL_CODE: string
}

export interface SchoolInfoParam {
/** 시도교육청코드 */
readonly ATPT_OFCDC_SC_CODE?: string
Expand All @@ -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
/** 급식일자 */
Expand All @@ -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
/** 학교과정명 */
Expand Down Expand Up @@ -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
/** 시도교육청명 */
Expand All @@ -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
/** 학교종류명 */
Expand Down Expand Up @@ -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
/** 식사명 */
Expand All @@ -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
/** 주야과정명 */
Expand Down Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export const AE = 'B10'
export const AN = '3000037367'
export const SE = '7010057'
export const YMD = '20230302'

export const ELS = '7091414'
28 changes: 28 additions & 0 deletions tests/timetable.test.ts
Original file line number Diff line number Diff line change
@@ -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<ElsTimetableResponse[]>(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<ElsTimetableResponse>(data)
})
})

0 comments on commit 4067d2e

Please sign in to comment.