feat: add originalSubject and originalTeacher

This commit is contained in:
Starcea 2024-07-14 20:36:01 +09:00
commit a1e506b7b2
No known key found for this signature in database
GPG key ID: B7A77E32374911E1
3 changed files with 31 additions and 7 deletions

View file

@ -2,7 +2,7 @@ import axios from 'axios'
import { BASE_URL, USER_AGENT } from './constants'
import DataManager from './data'
import School from './models/School'
import type Timetable from './models/Timetable'
import type { Timetable } from './models/Timetable'
import { encodeBase64, encodeEUCKR } from './utils/encode'
import { parseResponse } from './utils/parse'
@ -64,13 +64,26 @@ export default class Comcigan {
cls.slice(1).map((day, dIdx) =>
day.slice(1).map((period, pIdx) => {
const p = period.toString()
const changed =
period !== original[gIdx + 1][cIdx + 1][dIdx + 1][pIdx + 1]
return {
subject: subjects[Number(p.slice(0, p.length - teachersLen - 1))],
teacher: teachers[Number(p.slice(-teachersLen))],
changed:
period !== original[gIdx + 1][cIdx + 1][dIdx + 1][pIdx + 1],
}
changed,
...(changed
? {
originalSubject:
subjects[
original[gIdx + 1][cIdx + 1][dIdx + 1][pIdx + 1]
],
originalTeacher:
teachers[
original[gIdx + 1][cIdx + 1][dIdx + 1][pIdx + 1]
],
}
: {}),
} as Timetable
}),
),
),

View file

@ -1,7 +1,7 @@
import Comcigan from '../client'
import Fetcher from './Fetcher'
import type Region from './Region'
import type Timetable from './Timetable'
import type { Timetable } from './Timetable'
interface ISchool {
/** 학교 코드 */

View file

@ -1,8 +1,19 @@
export default interface Timetable {
export type Timetable = {
/** 과목 */
subject: string
/** 교사 */
teacher: string
/** 변경 여부 */
changed: boolean
}
} & (
| {
changed: true
/** 변경 전 과목 */
originalSubject: string
/** 변경 전 교사 */
originalTeacher: string
}
| {
changed: false
}
)