Skip to content

Commit

Permalink
Short circuit grades without any registrations
Browse files Browse the repository at this point in the history
  • Loading branch information
junlarsen committed Feb 8, 2024
1 parent 19f40c1 commit 5fbacb4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions apps/grades/src/server/job-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ export class JobServiceImpl implements JobService {
build: (queue, concurrency) => {
this.logger.info(`Processing grades using async queue with ${concurrency} concurrency`)
for (const grade of grades) {
const studentsWithGrade = parseInt(grade["Antall kandidater totalt"])
if (studentsWithGrade === 0) {
continue
}

queue.add(async () => {
// We need a reference to the subject from the reference id given by HKDir
const subject = await this.subjectRepository.getSubjectByReferenceId(grade.Emnekode)
Expand All @@ -141,17 +146,19 @@ export class JobServiceImpl implements JobService {
return
}

const year = parseInt(grade.Årstall)

// First we need to get or insert the matching grade.
let existingGrade = await this.gradeRepository.getGradeBySemester(
subject.id,
mapHkdirSemesterToSeason(grade.Semester),
parseInt(grade.Årstall)
year
)
if (existingGrade === null) {
existingGrade = await this.gradeRepository.createGrade({
subjectId: subject.id,
season: mapHkdirSemesterToSeason(grade.Semester),
year: parseInt(grade.Årstall),
year,
grade: 0,
})
}
Expand All @@ -161,7 +168,7 @@ export class JobServiceImpl implements JobService {
const previousWriteLogEntry = await this.gradeRepository.getPreviousWriteLogEntry(
existingGrade.subjectId,
mapHkdirSemesterToSeason(grade.Semester),
parseInt(grade.Årstall),
year,
grade.Karakter
)
if (previousWriteLogEntry !== null) {
Expand All @@ -170,7 +177,6 @@ export class JobServiceImpl implements JobService {

// Then we need to update the grade distribution for the current grade
const key = mapHkdirGradeToGrade(grade.Karakter)
const studentsWithGrade = parseInt(grade["Antall kandidater totalt"])
await this.gradeRepository.updateGrade(
existingGrade.id,
{
Expand Down

0 comments on commit 5fbacb4

Please sign in to comment.