Enhance weather data handling in FalukantService and update localization files
- Modified the FalukantService to explicitly load weather data for all regions, ensuring accurate weather information is associated with branches. - Updated the return logic to utilize the newly loaded weather data, improving data accuracy in branch responses. - Added new random event messages in both German and English localization files, enhancing user experience with richer event descriptions.
This commit is contained in:
@@ -490,7 +490,7 @@ class FalukantService extends BaseService {
|
||||
{
|
||||
model: RegionData,
|
||||
as: 'region',
|
||||
attributes: ['name'],
|
||||
attributes: ['id', 'name'],
|
||||
include: [
|
||||
{
|
||||
model: Weather,
|
||||
@@ -507,11 +507,27 @@ class FalukantService extends BaseService {
|
||||
attributes: ['id', 'regionId'],
|
||||
order: [['branchTypeId', 'ASC']]
|
||||
});
|
||||
return bs.map(b => ({
|
||||
...b.toJSON(),
|
||||
isMainBranch: u.mainBranchRegionId === b.regionId,
|
||||
weather: b.region?.weather?.weatherType?.tr || null
|
||||
}));
|
||||
|
||||
// Lade Wetter explizit für alle Regionen, um sicherzustellen, dass es korrekt geladen wird
|
||||
const regionIds = [...new Set(bs.map(b => b.regionId))];
|
||||
const weathers = await Weather.findAll({
|
||||
where: { regionId: { [Op.in]: regionIds } },
|
||||
include: [
|
||||
{ model: WeatherType, as: 'weatherType', attributes: ['tr'] }
|
||||
]
|
||||
});
|
||||
const weatherMap = new Map(weathers.map(w => [w.regionId, w.weatherType?.tr || null]));
|
||||
|
||||
return bs.map(b => {
|
||||
const branchJson = b.toJSON();
|
||||
// Verwende das explizit geladene Wetter, falls vorhanden, sonst das aus der Include-Beziehung
|
||||
const weather = weatherMap.get(b.regionId) || branchJson.region?.weather?.weatherType?.tr || null;
|
||||
return {
|
||||
...branchJson,
|
||||
isMainBranch: u.mainBranchRegionId === b.regionId,
|
||||
weather: weather
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async createBranch(hashedUserId, cityId, branchTypeId) {
|
||||
|
||||
Reference in New Issue
Block a user