🚑 Fix insert/delete loop if plans have same date

- Fix loop if multiple plans have the same date but different data
- Instead join them into one single plan to parse all substitutions
- Swap teacher and changedTeacher of "Sondereinsa." substitutions
This commit is contained in:
2023-06-20 15:40:05 +02:00
parent 1bfd156a03
commit 8b3809aeda

View File

@ -34,8 +34,16 @@ export class Parser {
succeeded: true,
},
});
// Insert substitutions of all substitution plans
// Group plans by date to prevent having
// multiple plan files with the same date
const dayPlans = [];
for (const plan of plans) {
const foundPlan = dayPlans.find((e) => e.date == plan.date);
if (!foundPlan) dayPlans.push(plan);
else foundPlan.changes.push(...plan.changes);
}
// Insert substitutions of all substitution plans
for (const plan of dayPlans) {
await this.insertSubstitutions(plan, parseEvent);
}
} catch (error) {
@ -77,6 +85,10 @@ export class Parser {
if (change.type == "Sondereins." && !change.subject) {
change.subject = change.notes;
}
if (change.type == "Sondereins." && !change.teacher) {
change.teacher = change.changedTeacher;
change.changedTeacher = "";
}
// Check if a substitution exists in the database that
// it similar enough to the entry in the substitution