Skip to content

Commit

Permalink
feat: classInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
star0202 committed May 4, 2023
1 parent 909439f commit ea8d8ee
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NeisRequest } from './http'
import type {
AcaInsTiInfoParam,
ClassInfoParam,
ElsTimetableParam,
HisTimetableParam,
MealServiceDietInfoParam,
Expand Down Expand Up @@ -79,6 +80,14 @@ export class Neis extends NeisRequest {
async getSpsTimetableOne(params: SpsTimetableParam) {
return firstOf(this.spsTimetableRaw(params))
}

async getClassInfo(params: ClassInfoParam) {
return this.classInfoRaw(params)
}

async getClassInfoOne(params: ClassInfoParam) {
return firstOf(this.classInfoRaw(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 @@ -2,6 +2,8 @@ import { ErrorsMapping } from './errors'
import type {
AcaInsTiInfoParam,
AcaInsTiInfoResponse,
ClassInfoParam,
ClassInfoResponse,
ElsTimetableParam,
ElsTimetableResponse,
HisTimetableParam,
Expand Down Expand Up @@ -101,6 +103,10 @@ export class NeisRequest {
return this.get<SpsTimetableResponse>('spsTimetable', params)
}

protected async classInfoRaw(params: ClassInfoParam) {
return this.get<ClassInfoResponse>('classInfo', params)
}

private async get<T>(endpoint: string, params: Params) {
return this.request<T>('GET', endpoint, params)
}
Expand Down
35 changes: 35 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ export interface SpsTimetableParam extends ElsTimetableParam {
readonly CLRM_NM?: string
}

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

export type Params =
| SchoolInfoParam
| MealServiceDietInfoParam
Expand All @@ -131,6 +146,7 @@ export type Params =
| MisTimetableParam
| HisTimetableParam
| SpsTimetableParam
| ClassInfoParam

interface BaseSchoolResponse {
/** 시도교육청코드 */
Expand Down Expand Up @@ -332,3 +348,22 @@ export interface SpsTimetableResponse extends ElsTimetableResponse {
/** 강의실명 */
readonly CLRM_NM: string
}

export interface ClassInfoResponse extends BaseSchoolResponse {
/** 학년도 */
readonly AY: string
/** 학년 */
readonly GRADE: string
/** 주야과정명 */
readonly DGHT_CRSE_SC_NM: string | null
/** 학교과정명 */
readonly SCHUL_CRSE_SC_NM: string
/** 계열명 */
readonly ORD_SC_NM: string | null
/** 학과명 */
readonly DDDEP_NM: string | null
/** 반명 */
readonly CLASS_NM: string
/** 수정일 */
readonly LOAD_DTM: string
}
24 changes: 24 additions & 0 deletions tests/ClassInfo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { ClassInfoResponse } from '../src'
import { AE, SE } from './constants'
import { neis } from './utils'

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

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

it('should return ClassInfoResponse', async () => {
const data = await neis.getClassInfoOne({
ATPT_OFCDC_SC_CODE: AE,
SD_SCHUL_CODE: SE,
GRADE: '1',
})

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

0 comments on commit ea8d8ee

Please sign in to comment.