✨ Mark non-existent substitutions as removed
This commit is contained in:
@ -94,6 +94,7 @@ export class Parser {
|
||||
const knownSubstitutions = await prisma.substitution.findMany({
|
||||
where: {
|
||||
date: new Date(new Date(date).setUTCHours(0, 0, 0, 0)),
|
||||
removed: false,
|
||||
},
|
||||
});
|
||||
|
||||
@ -107,15 +108,19 @@ export class Parser {
|
||||
change.subject = change.notes;
|
||||
}
|
||||
|
||||
const matchingSubstitution = knownSubstitutions.find((substitution) => {
|
||||
return substitution.date == new Date(date).setUTCHours(0, 0, 0, 0) &&
|
||||
substitution.type == (change.type == "Entfall")
|
||||
? "cancellation"
|
||||
: "change" &&
|
||||
substitution.lesson == change.lesson &&
|
||||
classes.sort().join(",") == substitution.class.sort().join(",") &&
|
||||
substitution.changedSubject == change.subject;
|
||||
});
|
||||
const matchingSubstitutionId = knownSubstitutions.findIndex(
|
||||
(substitution) => {
|
||||
return substitution.date == new Date(date).setUTCHours(0, 0, 0, 0) &&
|
||||
substitution.type == (change.type == "Entfall")
|
||||
? "cancellation"
|
||||
: "change" &&
|
||||
substitution.lesson == change.lesson &&
|
||||
classes.sort().join(",") ==
|
||||
substitution.class.sort().join(",") &&
|
||||
substitution.changedSubject == change.subject;
|
||||
}
|
||||
);
|
||||
const matchingSubstitution = knownSubstitutions[matchingSubstitutionId];
|
||||
|
||||
if (!matchingSubstitution) {
|
||||
const newSubstitution = await prisma.substitution.create({
|
||||
@ -176,8 +181,31 @@ export class Parser {
|
||||
`Substitution unchanged: S:${matchingSubstitution.id}`
|
||||
);
|
||||
}
|
||||
knownSubstitutions.splice(matchingSubstitutionId, 1);
|
||||
}
|
||||
}
|
||||
for (const remainingSubstitution of knownSubstitutions) {
|
||||
await prisma.substitution.update({
|
||||
where: {
|
||||
id: remainingSubstitution.id,
|
||||
},
|
||||
data: {
|
||||
removed: true,
|
||||
},
|
||||
});
|
||||
const substitutionChange = await prisma.substitutionChange.create({
|
||||
data: {
|
||||
substitutionId: remainingSubstitution.id,
|
||||
type: "deletion",
|
||||
changes: {},
|
||||
parseEventId: parseEvent.id,
|
||||
},
|
||||
});
|
||||
log(
|
||||
"Insert / DB",
|
||||
`Deleted removed substitution: S:${remainingSubstitution.id} C:${substitutionChange.id}`
|
||||
);
|
||||
}
|
||||
}
|
||||
getSubstitutionClasses(classList, classString) {
|
||||
const matchingClasses = classList.filter((element) => {
|
||||
|
Reference in New Issue
Block a user