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