Skip to content

Commit

Permalink
fix: update task result count calculation (#2460)
Browse files Browse the repository at this point in the history
  • Loading branch information
valerydluski authored Apr 13, 2024
1 parent aae8021 commit 9654337
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 10 additions & 1 deletion nestjs/src/courses/course-tasks/course-tasks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as dayjs from 'dayjs';
import { TaskResult } from '@entities/taskResult';
import { TaskInterviewResult } from '@entities/taskInterviewResult';
import { TaskSolution } from '@entities/taskSolution';
import { StageInterview } from '@entities/index';

export enum Status {
Started = 'started',
Expand Down Expand Up @@ -73,18 +74,26 @@ export class CourseTasksService {
.select('ct.id', 'id')
.addSelect('COUNT(r.id)', 'resultsCount')
.addSelect('COUNT(i.id)', 'interviewResultsCount')
.addSelect('COUNT(CASE WHEN si.score > 0 THEN 1 END)', 'stageInterviewResultsCount')
.leftJoin(TaskResult, 'r', 'r.courseTaskId = ct.id')
.leftJoin(TaskInterviewResult, 'i', 'i.courseTaskId = ct.id')
.leftJoin(StageInterview, 'si', 'si.courseTaskId = ct.id')
.where('ct.courseId = :courseId', { courseId })
.groupBy('ct.id')
.getRawMany<{ id: number; resultsCount: number; interviewResultsCount: number }>(),
.getRawMany<{
id: number;
resultsCount: number;
interviewResultsCount: number;
stageInterviewResultsCount: number;
}>(),
]);
return courseTasks.map(courseTask => {
const result = courseTaskResults.find(({ id }) => id === courseTask.id);
return {
...courseTask,
resultsCount: Number(result?.resultsCount || 0),
interviewResultsCount: Number(result?.interviewResultsCount || 0),
stageInterviewResultsCount: Number(result?.stageInterviewResultsCount ?? 0),
};
});
}
Expand Down
11 changes: 9 additions & 2 deletions nestjs/src/courses/course-tasks/dto/course-task-detailed.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ import { CourseTaskDto } from './course-task.dto';

@ApiResponse({})
export class CourseTaskDetailedDto extends CourseTaskDto {
constructor(courseTask: CourseTask & { resultsCount?: number; interviewResultsCount?: number }) {
constructor(
courseTask: CourseTask & {
resultsCount?: number;
interviewResultsCount?: number;
stageInterviewResultsCount?: number;
},
) {
super(courseTask);
this.publicAttributes = courseTask.task?.attributes?.['public'] ?? {};
this.githubRepoName = courseTask.task.githubRepoName;
this.sourceGithubRepoUrl = courseTask.task.sourceGithubRepoUrl;
this.resultsCount = courseTask.resultsCount || courseTask.interviewResultsCount || 0;
this.resultsCount =
courseTask.resultsCount || courseTask.interviewResultsCount || courseTask.stageInterviewResultsCount || 0;
}

@ApiProperty()
Expand Down

0 comments on commit 9654337

Please sign in to comment.