Skip to content

Commit

Permalink
add: isAnnual
Browse files Browse the repository at this point in the history
  • Loading branch information
SIY1121 committed Apr 3, 2021
1 parent 192c7bd commit d6c19ea
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion __tests__/usecase/updateCourseDatabase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test('強制更新', async () => {
compareCourseWithoutId(d!, c)
})
)
})
}, 10000)

test('不正データ', async () => {
const brokenData = [...initialData]
Expand Down
1 change: 1 addition & 0 deletions protos/CourseService.proto
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ message Course {
repeated CourseMethod methods = 11;
repeated CourseSchedule schedules = 12;
bool hasParseError = 13; // パースエラーが発生した場合(情報の信憑性が薄い場合)trueになる
bool isAnnual = 14; // 通年フラグ
}

message GetCoursesRequest {
Expand Down
7 changes: 7 additions & 0 deletions src/database/model/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ export class Course {
})
hasParseError!: boolean

@Column({
name: 'is_annual',
type: 'bool',
default: false,
})
isAnnual!: boolean

@OneToMany(() => CourseRecommendedGrade, (r) => r.courseId, {
cascade: true,
onDelete: 'CASCADE',
Expand Down
25 changes: 24 additions & 1 deletion src/grpc/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,30 @@ export function createDBCourse(c: PCourse, year: number, id: string): Course {
mm.method = m
return mm
})
target.schedules = c.schedules.map((s) => {

// 通年かどうか
target.isAnnual = !!c.schedules.find((s) => s.module === PModule.Annual)

// 通年のスケジュールを春ABC秋ABCに変換
const schedules = c.schedules
.map((s) =>
s.module === PModule.Annual
? [
PModule.SpringA,
PModule.SpringB,
PModule.SpringC,
PModule.FallA,
PModule.FallB,
PModule.FallC,
].map((m) => ({
...s,
module: m,
}))
: s
)
.flat()

target.schedules = schedules.map((s) => {
const r = new CourseSchedule()
r.module = createDBModule(s.module)
r.day = createDBDay(s.day)
Expand Down

0 comments on commit d6c19ea

Please sign in to comment.