Skip to content

Commit

Permalink
update: number enum to string enum
Browse files Browse the repository at this point in the history
  • Loading branch information
SIY1121 committed Mar 29, 2021
1 parent 1c1546a commit d6fd89e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
50 changes: 25 additions & 25 deletions src/database/model/enums.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
export enum CourseMethod {
OnlineAsynchronous,
OnlineSynchronous,
FaceToFace,
Others,
OnlineAsynchronous = 'OnlineAsynchronous',
OnlineSynchronous = 'OnlineSynchronous',
FaceToFace = 'FaceToFace',
Others = 'Others',
}

export enum Module {
SpringA,
SpringB,
SpringC,
FallA,
FallB,
FallC,
SummerVacation,
SpringVacation,
Annual,
Unknown,
SpringA = 'SpringA',
SpringB = 'SpringB',
SpringC = 'SpringC',
FallA = 'FallA',
FallB = 'FallB',
FallC = 'FallC',
SummerVacation = 'SummerVacation',
SpringVacation = 'SpringVacation',
Annual = 'Annual',
Unknown = 'Unknown',
}

export enum Day {
Sun,
Mon,
Tue,
Wed,
Thu,
Fri,
Sat,
Intensive,
Appointment,
AnyTime,
Unknown,
Sun = 'Sun',
Mon = 'Mon',
Tue = 'Tue',
Wed = 'Wed',
Thu = 'Thu',
Fri = 'Fri',
Sat = 'Sat',
Intensive = 'Intensive',
Appointment = 'Appointment',
AnyTime = 'AnyTime',
Unknown = 'Unknown',
}
7 changes: 2 additions & 5 deletions src/grpc/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import {
*/
export function createDBModule(m: PModule): Module {
return (
Module[Module[Object.values(PModule).indexOf(m)] as keyof typeof Module] ??
Module.Unknown
Object.values(Module)[Object.values(PModule).indexOf(m)] ?? Module.Unknown
)
}

Expand All @@ -37,9 +36,7 @@ export function createDBModule(m: PModule): Module {
* @param d パーサのDay
*/
export function createDBDay(d: PDay): Day {
return (
Day[Day[Object.values(PDay).indexOf(d)] as keyof typeof Day] ?? Day.Unknown
)
return Object.values(Day)[Object.values(PDay).indexOf(d)] ?? Day.Unknown
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/grpc/course.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from '../../generated'
import { toGrpcError } from './converter'
import { searchCourseUseCase } from '../usecase/searchCourse'
import { Day, Module } from '../database/model/enums'
import { CourseMethod, Day, Module } from '../database/model/enums'

/**
* grpcサーバのCourseService実装
Expand Down Expand Up @@ -129,8 +129,12 @@ function createGrpcCourse({
return {
lastUpdate: lastUpdate.toISOString(),
recommendedGrades: recommendedGrades.map((r) => r.grade),
methods: methods.map((m) => m.method),
schedules: (schedules as unknown) as ICourseSchedule[],
methods: methods.map((m) => Object.values(CourseMethod).indexOf(m.method)),
schedules: schedules.map(({ module, day, ...s }) => ({
module: Object.keys(Module).indexOf(module),
day: Object.keys(Day).indexOf(day),
...s,
})),
...c,
}
}
Expand Down

0 comments on commit d6fd89e

Please sign in to comment.