Skip to content

Commit

Permalink
fix: thanks untis for not returning 90% of classes
Browse files Browse the repository at this point in the history
  • Loading branch information
bddvlpr committed Oct 2, 2023
1 parent f3ea3e2 commit f2c0cff
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/untis/untis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,31 +111,22 @@ export class UntisService {
const currentMoment = moment().subtract(before, 'days');
const endMoment = moment().add(after, 'days');

let lessonsRange = await this.fetchTimetableRange(
currentMoment.toDate(),
endMoment.toDate(),
classId,
).catch(() => null);

if (!lessonsRange) {
this.logger.warn(
'Range fetch failed, falling back on individual date fetch.',
const promises = [];
while (currentMoment.isBefore(endMoment)) {
promises.push(
this.fetchTimetableFor(currentMoment.toDate(), classId),
);
const promises = [];
while (currentMoment.isBefore(endMoment)) {
promises.push(
this.fetchTimetableFor(currentMoment.toDate(), classId),
);
currentMoment.add(1, 'days');
}
lessonsRange = (await Promise.all(promises)).filter((l) => l).flat();
currentMoment.add(1, 'days');
}
return lessonsRange;
return (await Promise.all(promises)).filter((l) => l).flat();
},
60_000,
);
}

/**
* @deprecated
*/
private fetchTimetableRange(
start: Date,
end: Date,
Expand Down

0 comments on commit f2c0cff

Please sign in to comment.