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; + } } };