feat(falukant): enhance reputation handling in character checks
All checks were successful
Deploy to production / deploy (push) Successful in 2m52s

- Added the 'reputation' attribute to the character query in FalukantService, improving data retrieval for nobility requirements.
- Refactored the `checkReputationRequirement` method to streamline reputation checks, ensuring it handles undefined or null values more effectively, enhancing reliability in user character evaluations.
This commit is contained in:
Torsten Schulz (local)
2026-04-10 08:45:54 +02:00
parent 3450bac99c
commit 7e0821c96b

View File

@@ -905,7 +905,8 @@ class FalukantService extends BaseService {
{ model: FalukantPredefineLastname, as: 'definedLastName', attributes: ['name'] },
{ model: TitleOfNobility, as: 'nobleTitle', attributes: ['labelTr', 'id'] }
],
attributes: ['id', 'birthdate', 'gender', 'moodId', 'health']
// reputation: für Adel-Voraussetzungen u.a. (checkReputationRequirement nutzt user.character ohne Nachladen)
attributes: ['id', 'birthdate', 'gender', 'moodId', 'health', 'reputation']
},
]
});
@@ -5905,11 +5906,15 @@ class FalukantService extends BaseService {
}
async checkReputationRequirement(user, requirement) {
const character = user.character || await FalukantCharacter.findOne({
where: { userId: user.id },
attributes: ['reputation']
});
return Number(character?.reputation || 0) >= Number(requirement.requirementValue || 0);
let rep = user.character?.reputation;
if (rep === undefined || rep === null) {
const row = await FalukantCharacter.findOne({
where: { userId: user.id },
attributes: ['reputation']
});
rep = row?.reputation;
}
return Number(rep ?? 0) >= Number(requirement.requirementValue || 0);
}
async checkHousePositionRequirement(user, requirement) {