Skip to content

Commit

Permalink
feat: tiClrminfo
Browse files Browse the repository at this point in the history
  • Loading branch information
star0202 committed May 4, 2023
1 parent b76734e commit 7174f9d
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
SchoolScheduleParam,
SchulAflcoinfoParam,
SpsTimetableParam,
TiClrminfoParam,
} from './types'

export class Neis extends NeisRequest {
Expand Down Expand Up @@ -128,6 +129,16 @@ export class Neis extends NeisRequest {
async getAflcoOne(params: SchulAflcoinfoParam) {
return firstOf(this.schulAflcoinfoRaw(params))
}

/** tiClrminfo */
async getClrm(params: TiClrminfoParam) {
return this.tiClrminfoRaw(params)
}

/** tiClrminfo */
async getClrmOne(params: TiClrminfoParam) {
return firstOf(this.tiClrminfoRaw(params))
}
}

const firstOf = <T>(promise: Promise<T[]>) => promise.then((res) => res[0])
6 changes: 6 additions & 0 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import type {
SchulAflcoinfoResponse,
SpsTimetableParam,
SpsTimetableResponse,
TiClrminfoParam,
TiClrminfoResponse,
} from './types'
import type { AxiosInstance, AxiosRequestConfig } from 'axios'
import axios from 'axios'
Expand Down Expand Up @@ -119,6 +121,10 @@ export class NeisRequest {
return this.get<SchulAflcoinfoResponse>('schulAflcoinfo', params)
}

protected async tiClrminfoRaw(params: TiClrminfoParam) {
return this.get<TiClrminfoResponse>('tiClrminfo', params)
}

private async get<T>(endpoint: string, params: Params) {
return this.request<T>('GET', endpoint, 5000, params)
}
Expand Down
39 changes: 39 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ export interface SchulAflcoinfoParam extends DefaultParamWithSchoolParam {
readonly DGHT_CRSE_SC_NM?: string
}

export interface TiClrminfoParam extends DefaultParamWithSchoolParam {
/** 학년도 */
readonly AY?: string
/** 학년 */
readonly GRADE?: string
/** 학기 */
readonly SEM?: string
/** 학교과정명 */
readonly SCHUL_CRSE_SC_NM?: string
/** 주야과정명 */
readonly DGHT_CRSE_SC_NM?: string
/** 계열명 */
readonly ORD_SC_NM?: string
/** 학과명 */
readonly DDDEP_NM?: string
}

export type Params =
| SchoolInfoParam
| MealServiceDietInfoParam
Expand All @@ -161,6 +178,7 @@ export type Params =
| ClassInfoParam
| SchoolMajorinfoParam
| SchulAflcoinfoParam
| TiClrminfoParam

interface BaseSchoolResponse {
/** 시도교육청코드 */
Expand Down Expand Up @@ -401,3 +419,24 @@ export interface SchulAflcoinfoResponse extends BaseSchoolResponse {
/** 수정일 */
readonly LOAD_DTM: string
}

export interface TiClrminfoResponse extends BaseSchoolResponse {
/** 학년도 */
readonly AY: string
/** 학년 */
readonly GRADE: string
/** 학기 */
readonly SEM: string
/** 학교과정명 */
readonly SCHUL_CRSE_SC_NM: string
/** 주야과정명 */
readonly DGHT_CRSE_SC_NM: string
/** 계열명 */
readonly ORD_SC_NM: string
/** 학과명 */
readonly DDDEP_NM: string
/** 강의실명 */
readonly CLRM_NM: string
/** 수정일 */
readonly LOAD_DTM: string
}
26 changes: 26 additions & 0 deletions tests/TiClrminfo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { TiClrminfoResponse } from '../src'
import { AE, SE } from './constants'
import { neis } from './utils'

describe('TiClrminfo', () => {
it('should return TiClrminfoResponse[]', async () => {
const data = await neis.getClrm({
ATPT_OFCDC_SC_CODE: AE,
SD_SCHUL_CODE: SE,
})

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

it('should return TiClrminfoResponse', async () => {
const data = await neis.getClrmOne({
ATPT_OFCDC_SC_CODE: AE,
SD_SCHUL_CODE: SE,
AY: '2023',
GRADE: '1',
SEM: '1',
})

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

0 comments on commit 7174f9d

Please sign in to comment.