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.
This commit is contained in:
@@ -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', {
|
||||
|
||||
Reference in New Issue
Block a user