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.

This commit is contained in:
Torsten Schulz (local)
2026-02-04 14:20:22 +01:00
parent d038d72cde
commit bbc3354f16

View File

@@ -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({
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 },