From a44607f8a55cb03695fa71b8edae6097f8b8fd3e Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Fri, 29 Aug 2025 13:58:43 +0200 Subject: [PATCH] feat(backend): Verbesserung der Initialisierung von Haustypen in initializeFalukantTypes.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Hinzufügen einer Fehlerbehandlung für fehlende minimale Adelstitel während der Erstellung von Haustypen. - Verbesserung der Konsolenausgaben zur besseren Nachverfolgbarkeit von Warnungen und Fehlern. - Sicherstellung, dass nur gültige Haustypen erstellt werden, um Dateninkonsistenzen zu vermeiden. --- .../utils/falukant/initializeFalukantTypes.js | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/backend/utils/falukant/initializeFalukantTypes.js b/backend/utils/falukant/initializeFalukantTypes.js index e9daa35..ddc57fa 100644 --- a/backend/utils/falukant/initializeFalukantTypes.js +++ b/backend/utils/falukant/initializeFalukantTypes.js @@ -799,15 +799,32 @@ export const initializePromotionalGiftMoodLinks = async () => { export const initializeFalukantHouseTypes = async () => { for (const ht of houseTypes) { - const [record, created] = await HouseType.findOrCreate({ - where: { labelTr: ht.abbr }, - defaults: { - cost: ht.cost, - imageUrl: null, - position: ht.position, - minimumNobleTitle: await TitleOfNobility.findOne({ where: { labelTr: ht.minimumTitle } }).then(title => title.id), + try { + // Finde den minimalen Adelstitel + const minimumTitle = await TitleOfNobility.findOne({ where: { labelTr: ht.minimumTitle } }); + + if (!minimumTitle) { + console.warn(`⚠️ Warnung: Titel '${ht.minimumTitle}' für Haustyp '${ht.abbr}' nicht gefunden. Überspringe...`); + continue; } - }); + + const [record, created] = await HouseType.findOrCreate({ + where: { labelTr: ht.abbr }, + defaults: { + cost: ht.cost, + imageUrl: null, + position: ht.position, + minimumNobleTitle: minimumTitle.id, + } + }); + + if (created) { + console.log(`✅ Haustyp '${ht.abbr}' erstellt`); + } + } catch (error) { + console.error(`❌ Fehler beim Erstellen des Haustyps '${ht.abbr}':`, error.message); + throw error; + } } };