diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index 93b4ddf..8b7bc39 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -2821,9 +2821,15 @@ class FalukantService extends BaseService { if (!ptype || !music || !banquette) { throw new Error('Ungültige Party-, Musik- oder Bankett-Auswahl'); } - const nobilities = nobilityIds.length + const nobilities = nobilityIds && nobilityIds.length ? await TitleOfNobility.findAll({ where: { id: { [Op.in]: nobilityIds } } }) : []; + + // Prüfe, ob alle angegebenen IDs gefunden wurden + if (nobilityIds && nobilityIds.length > 0 && nobilities.length !== nobilityIds.length) { + throw new Error('Einige ausgewählte Adelstitel existieren nicht'); + } + let cost = (ptype.cost || 0) + (music.cost || 0) + (banquette.cost || 0); cost += (50 / servantRatio - 1) * 1000; const nobilityCost = nobilities.reduce((sum, n) => sum + ((n.id ^ 5) * 1000), 0); @@ -2848,8 +2854,9 @@ class FalukantService extends BaseService { servantRatio, cost: cost }); - if (nobilityIds.length) { - await party.addInvitedNobilities(nobilityIds); + if (nobilities.length > 0) { + // Verwende die bereits geladenen Objekte + await party.addInvitedNobilities(nobilities); } const user = await User.findByPk(falukantUser.userId); notifyUser(user.hashedId, 'falukantPartyUpdate', {