Skip to content

Commit

Permalink
Revert "feat: update schedule sort rules (#2364)" (#2365)
Browse files Browse the repository at this point in the history
This reverts commit bb8e5e8.
  • Loading branch information
valerydluski authored Nov 18, 2023
1 parent bb8e5e8 commit eb5a503
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions nestjs/src/courses/course-schedule/course-schedule.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { PersonDto } from '../../core/dto';
import { Repository } from 'typeorm';
import { EventType } from '../course-events/dto/course-event.dto';
import { Course } from '@entities/course';
import dayjs from 'dayjs';

export type CourseScheduleItem = Pick<CourseTask, 'id' | 'courseId'> &
Partial<Pick<CourseTask, 'maxScore' | 'scoreWeight'>> & {
Expand Down Expand Up @@ -71,24 +70,6 @@ export class CourseScheduleService {
readonly taskCheckerRepository: Repository<TaskChecker>,
) {}

private scheduleSort(a: CourseScheduleItem, b: CourseScheduleItem) {
const tagPriority: { [key in CourseScheduleItemTag]?: number } = {
'self-study': 1,
test: 2,
coding: 3,
};

const timeDifference = dayjs(a.startDate).diff(dayjs(b.startDate), 'minute');
if (timeDifference !== 0) {
return timeDifference;
}

const aTagPriority = tagPriority[a.tag] || Infinity;
const bTagPriority = tagPriority[b.tag] || Infinity;

return aTagPriority - bTagPriority;
}

public async getAll(courseId: number, studentId?: number): Promise<CourseScheduleItem[]> {
const [courseTasks, courseEvents] = await Promise.all([
this.getActiveCourseTasks(courseId, studentId),
Expand Down Expand Up @@ -164,7 +145,7 @@ export class CourseScheduleService {
} as CourseScheduleItem;
}),
)
.sort(this.scheduleSort);
.sort((a, b) => a.startDate.getTime() - b.startDate.getTime());

return schedule;
}
Expand Down

0 comments on commit eb5a503

Please sign in to comment.