From 820b5e85700d2e642febf332b8201f8a870428f2 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Tue, 23 Dec 2025 10:51:22 +0100 Subject: [PATCH] Enhance health management in FalukantService to improve user feedback and error handling - Updated health deduction logic to clarify the distinction between health and monetary costs. - Added error handling for money update failures to ensure robust transaction processing. - Modified return value to include updated health status, providing clearer information for UI updates. --- backend/services/falukantService.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index 45e0fcb..777268e 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -4189,7 +4189,7 @@ class FalukantService extends BaseService { if (user.money - activityObject.cost < 0) { throw new Error('no money'); } - user.character.health -= activityObject.cost; + // Hinweis: health ist ein Status (0..100) und darf nicht mit Geldkosten vermischt werden. const healthChange = await this[activityObject.method](user); await HealthActivity.create({ characterId: user.character.id, @@ -4197,12 +4197,18 @@ class FalukantService extends BaseService { successPercentage: healthChange, cost: activityObject.cost }); - updateFalukantUserMoney(user.id, -activityObject.cost, 'health.' + activity); + const moneyResult = await updateFalukantUserMoney(user.id, -activityObject.cost, 'health.' + activity, user.id); + if (!moneyResult.success) throw new Error('Failed to update money'); // Status-Update Notification senden notifyUser(user.user.hashedId, 'falukantUpdateStatus', {}); - return { success: true }; + // Give client enough info to update UI without ambiguity + const updatedChar = await FalukantCharacter.findOne({ + where: { id: user.character.id }, + attributes: ['health'] + }); + return { success: true, delta: healthChange, health: updatedChar?.health ?? null }; } async healthChange(user, delta) {