🚑 Prevent duplicate substitutions

- Prevent duplication if two substitution plan files are the same
This commit is contained in:
2023-08-28 11:19:46 +02:00
parent 38246db16b
commit cce7bd55da

View File

@ -40,7 +40,17 @@ export class Parser {
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);
else {
for (const change of plan.changes) {
// Make sure to not insert the exact same substitution twice
const changeExists = foundPlan.changes.find(
(e) => JSON.stringify(e) == JSON.stringify(change),
);
if (!changeExists) {
foundPlan.changes.push(change);
}
}
}
}
// Insert substitutions of all substitution plans
for (const plan of dayPlans) {