Skip to content

Commit

Permalink
feat: integrate team distribution handling in course schedule transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
valerydluski committed Nov 6, 2024
1 parent 99dddca commit 61d65c7
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions nestjs/src/courses/course-schedule/course-schedule.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export class CourseScheduleService {
readonly courseTaskRepository: Repository<CourseTask>,
@InjectRepository(CourseEvent)
readonly courseEventRepository: Repository<CourseEvent>,
@InjectRepository(TeamDistribution)
readonly teamDistribution: Repository<TeamDistribution>,
@InjectRepository(TaskResult)
readonly taskResultRepository: Repository<TaskResult>,
@InjectRepository(TaskInterviewResult)
Expand Down Expand Up @@ -356,8 +358,14 @@ export class CourseScheduleService {
this.courseRepository.findOneByOrFail({ id: toCourseId }),
]);

const [courseTasks, courseEvents, courseTeamDistributions] = await Promise.all([
this.courseTaskRepository.find({ where: { courseId: fromCourseId } }),
this.courseEventRepository.find({ where: { courseId: fromCourseId } }),
this.teamDistribution.find({ where: { courseId: fromCourseId } }),
]);

const timeDiff = toCourse.startDate.getTime() - fromCourse.startDate.getTime();
const courseTasks = await this.courseTaskRepository.find({ where: { courseId: fromCourseId } });

for (const courseTask of courseTasks) {
const { id, createdDate, updatedDate, crossCheckStatus, ...newCourseTask } = courseTask;
newCourseTask.courseId = toCourseId;
Expand All @@ -368,7 +376,7 @@ export class CourseScheduleService {
newCourseTask.mentorEndDate = this.adjustDate(newCourseTask.mentorEndDate, timeDiff);
await this.courseTaskRepository.save(newCourseTask);
}
const courseEvents = await this.courseEventRepository.find({ where: { courseId: fromCourseId } });

for (const courseEvent of courseEvents) {
const { id, createdDate, updatedDate, ...newCourseEvent } = courseEvent;
newCourseEvent.courseId = toCourseId;
Expand All @@ -378,6 +386,16 @@ export class CourseScheduleService {
newCourseEvent.time = null;
await this.courseEventRepository.save(newCourseEvent);
}

for (const teamDistribution of courseTeamDistributions) {
const { id, createdDate, updatedDate, ...newTeamDistribution } = teamDistribution;
newTeamDistribution.courseId = toCourseId;
newTeamDistribution.startDate =
this.adjustDate(newTeamDistribution.startDate, timeDiff) ?? newTeamDistribution.startDate;
newTeamDistribution.endDate =
this.adjustDate(newTeamDistribution.endDate, timeDiff) ?? newTeamDistribution.endDate;
await this.teamDistribution.save(newTeamDistribution);
}
}

private adjustDate(date: string | Date | null, timeDiff: number): Date | null {
Expand Down

0 comments on commit 61d65c7

Please sign in to comment.