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:
@@ -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');
|
if (!u) throw new Error('User not found');
|
||||||
// Load UserHouse and HouseType in separate queries to avoid EagerLoadingError
|
// Load UserHouse and HouseType in separate queries to avoid EagerLoadingError
|
||||||
const userHouse = await UserHouse.findOne({
|
let userHouse = null;
|
||||||
where: { userId: u.id },
|
if (u.id != null) {
|
||||||
attributes: ['roofCondition', 'houseTypeId']
|
userHouse = await UserHouse.findOne({
|
||||||
});
|
where: { userId: u.id },
|
||||||
|
attributes: ['roofCondition', 'houseTypeId']
|
||||||
|
});
|
||||||
|
}
|
||||||
if (userHouse?.houseTypeId) {
|
if (userHouse?.houseTypeId) {
|
||||||
const houseType = await HouseType.findOne({
|
const houseType = await HouseType.findOne({
|
||||||
where: { id: userHouse.houseTypeId },
|
where: { id: userHouse.houseTypeId },
|
||||||
|
|||||||
Reference in New Issue
Block a user