🚑 Prevent duplicate substitutions within a file

This commit is contained in:
2023-08-28 12:14:40 +02:00
parent 607e304c50
commit c9e48fe8b4

View File

@ -39,10 +39,24 @@ export class Parser {
const dayPlans = [];
for (const plan of plans) {
const foundPlan = dayPlans.find((e) => e.date == plan.date);
if (!foundPlan) dayPlans.push(plan);
else {
if (!foundPlan) {
// Make sure to not insert duplicate substitutions within a file
const changes = structuredClone(plan.changes);
const cleanedChanges = [];
for (const change of changes) {
const changeExists = cleanedChanges.find(
(e) => JSON.stringify(e) == JSON.stringify(change),
);
if (!changeExists) {
cleanedChanges.push(change);
}
// Use the new array of changes
plan.changes = cleanedChanges;
}
dayPlans.push(plan);
} else {
for (const change of plan.changes) {
// Make sure to not insert the exact same substitution twice
// Make sure to not insert a substitution that already exists in the changes
const changeExists = foundPlan.changes.find(
(e) => JSON.stringify(e) == JSON.stringify(change),
);