Skip to content

Commit

Permalink
remove AverageGrade property after hotfix and filter null values, ref…
Browse files Browse the repository at this point in the history
…s 333
  • Loading branch information
mburri committed Apr 27, 2022
1 parent 5e89039 commit 287e438
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
9 changes: 3 additions & 6 deletions src/app/shared/models/course.model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as t from 'io-ts';
import { LocalDateTimeFromString, Maybe, Option } from './common-types';
import { LocalDateTimeFromString, Option } from './common-types';
import { Student } from './student.model';
import { StudyClass } from './study-class.model';
import { Result, Test } from './test.model';
import { Student } from './student.model';

const id = t.type({
Id: t.number,
Expand Down Expand Up @@ -37,10 +37,7 @@ const ExpandedAttendanceRef = t.partial({
const AttendanceRef = t.intersection([id, HRef, ExpandedAttendanceRef]);

const Grading = t.type({
// the property AverageGrade was renamed to AverageTestResult with a recent backend hotfix -
// change the property name when the hotfix reaches the development backend
AverageTestResult: Maybe(t.number),
AverageGrade: Maybe(t.number),
AverageTestResult: t.number,
CanGrade: t.boolean,
EventDesignation: t.string,
EventId: t.number,
Expand Down
8 changes: 7 additions & 1 deletion src/app/shared/models/student-grades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,17 @@ function getFinalGrade(student: Student, gradings: Grading[]): FinalGrade {
);

return {
average: grading?.AverageGrade || grading?.AverageTestResult,
average: toAverage(grading),
finalGradeId: grading?.GradeId,
};
}

function toAverage(grading: Grading | undefined) {
if (grading === undefined) return null;
if (grading.AverageTestResult === 0) return null;
return grading!.AverageTestResult;
}

export const compareFn = ({ key, ascending }: Sorting<SortKeys>) => (
sg1: StudentGrade,
sg2: StudentGrade
Expand Down
1 change: 0 additions & 1 deletion src/spec-builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ export function buildGrading(
): Grading {
return {
AverageTestResult: averageGrade,
AverageGrade: averageGrade,
CanGrade: false,
EventDesignation: 'Französisch-S2',
EventId: 9248,
Expand Down

0 comments on commit 287e438

Please sign in to comment.