From 8b3809aedae9cebc29a437db471b6cb839558681 Mon Sep 17 00:00:00 2001 From: minie4 Date: Tue, 20 Jun 2023 15:40:05 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20Fix=20insert/delete=20loop=20if?= =?UTF-8?q?=20plans=20have=20same=20date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- server/parser/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server/parser/index.js b/server/parser/index.js index 1535fd6..b4766a4 100644 --- a/server/parser/index.js +++ b/server/parser/index.js @@ -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