Skip to content

Commit 9ddc192

Browse files
committed
Minor fixes
1 parent a7091b3 commit 9ddc192

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

server/src/controllers/CohortsController.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ export class CohortsController implements CohortsControllerType {
4848

4949
// Sort trainees in each group
5050
Object.values(cohortDictionary).forEach((trainees) => {
51-
trainees?.sort(this.compareTraineeInCohort);
51+
trainees?.sort(this.compareTraineeInCohort.bind(this));
5252
});
5353
// Convert dictionary to array of cohorts
5454
const result: Cohort[] = Object.entries(cohortDictionary).map(([cohortNumber, trainees]) => {
5555
const cohortNumberInt = Number.parseInt(cohortNumber);
5656
return {
5757
cohort: isNaN(cohortNumberInt) ? null : cohortNumberInt,
58-
trainees: (trainees ?? []).map(this.getTraineeSummary),
58+
trainees: (trainees ?? []).map(this.getTraineeSummary.bind(this)),
5959
};
6060
});
6161
res.status(200).json(result);
@@ -76,16 +76,16 @@ export class CohortsController implements CohortsControllerType {
7676
LearningStatus: trainee.educationInfo.learningStatus,
7777
JobPath: trainee.employmentInfo.jobPath,
7878
strikes: trainee.educationInfo.strikes.length,
79-
averageTestScore: CohortsController.calculateAverageTestScore(trainee.educationInfo.tests),
79+
averageTestScore: this.calculateAverageTestScore(trainee.educationInfo.tests),
8080
};
8181
}
8282

83-
private static calculateAverageTestScore(tests: Test[]): number | null {
84-
const testsWithScores = tests.filter((test) => test.score !== undefined && test.score !== null);
83+
private calculateAverageTestScore(tests: Test[]): number | null {
84+
const testsWithScores = tests.filter((test) => test.score !== undefined);
8585
if (testsWithScores.length === 0) {
8686
return null;
8787
}
88-
const sum = testsWithScores.reduce((acc, test) => acc + (test.score as number), 0);
88+
const sum = testsWithScores.reduce((acc, test) => acc + (test.score ?? 0), 0);
8989
return sum / testsWithScores.length;
9090
}
9191

server/src/repositories/TraineesRepository.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export class MongooseTraineesRepository implements TraineesRepository {
7070
'personalInfo.hasWorkPermit',
7171
'educationInfo.learningStatus',
7272
'educationInfo.strikes.id',
73+
'educationInfo.tests.score',
7374
'educationInfo.currentCohort',
7475
'employmentInfo.jobPath',
7576
])

0 commit comments

Comments
 (0)