From b1d29f2083cdc2355bec55654cf63e78fc882c50 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Fri, 5 Dec 2025 20:49:12 +0100 Subject: [PATCH] Enhance nobility ID validation in FalukantService - Added checks to ensure that provided nobility IDs are valid and exist in the database, improving error handling and user feedback. - Updated logic to use loaded nobility objects when adding invited nobilities to a party, optimizing database interactions. --- backend/services/falukantService.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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', {