From bbc3354f16636f7b572352f87121befcb73f0234 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 4 Feb 2026 14:20:22 +0100 Subject: [PATCH] Refactor user house retrieval in FalukantService: Update logic to check for user ID before querying UserHouse, preventing unnecessary database calls and improving error handling. Maintain separate queries for UserHouse and relationships to avoid EagerLoadingError. --- backend/services/falukantService.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index c136a8a..8b018c3 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -406,14 +406,17 @@ class FalukantService extends BaseService { ] }, ], - attributes: ['money', 'creditAmount', 'todayCreditTaken',] + attributes: ['id', 'money', 'creditAmount', 'todayCreditTaken'] }); if (!u) throw new Error('User not found'); // Load UserHouse and HouseType in separate queries to avoid EagerLoadingError - const userHouse = await UserHouse.findOne({ - where: { userId: u.id }, - attributes: ['roofCondition', 'houseTypeId'] - }); + let userHouse = null; + if (u.id != null) { + userHouse = await UserHouse.findOne({ + where: { userId: u.id }, + attributes: ['roofCondition', 'houseTypeId'] + }); + } if (userHouse?.houseTypeId) { const houseType = await HouseType.findOne({ where: { id: userHouse.houseTypeId },