Enhance weather model and service logic; improve money history translation handling

- Added primary key to the Weather model for better data integrity.
- Updated FalukantService to include specific weather attributes in queries, enhancing data retrieval.
- Refactored money history view to utilize a dedicated translation method for improved localization handling.
This commit is contained in:
Torsten Schulz (local)
2025-12-02 14:05:25 +01:00
parent e57de7f983
commit 956418f5f3
3 changed files with 23 additions and 4 deletions

View File

@@ -9,13 +9,13 @@ Weather.init(
{ {
regionId: { regionId: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false, allowNull: false,
references: { references: {
model: RegionData, model: RegionData,
key: 'id', key: 'id',
schema: 'falukant_data' schema: 'falukant_data'
}, }
unique: true // Jede Stadt hat nur ein Wetter
}, },
weatherTypeId: { weatherTypeId: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,

View File

@@ -493,6 +493,7 @@ class FalukantService extends BaseService {
{ {
model: Weather, model: Weather,
as: 'weather', as: 'weather',
attributes: ['regionId', 'weatherTypeId'],
include: [ include: [
{ model: WeatherType, as: 'weatherType', attributes: ['tr'] } { model: WeatherType, as: 'weatherType', attributes: ['tr'] }
], ],
@@ -3146,13 +3147,18 @@ class FalukantService extends BaseService {
throw new Error('no money'); throw new Error('no money');
} }
user.character.health -= activityObject.cost; user.character.health -= activityObject.cost;
const healthChange = await this[activityObject.method](user);
await HealthActivity.create({ await HealthActivity.create({
characterId: user.character.id, characterId: user.character.id,
activityTr: activity, activityTr: activity,
successPercentage: await this[activityObject.method](user), successPercentage: healthChange,
cost: activityObject.cost cost: activityObject.cost
}); });
updateFalukantUserMoney(user.id, -activityObject.cost, 'health.' + activity); updateFalukantUserMoney(user.id, -activityObject.cost, 'health.' + activity);
// Status-Update Notification senden
notifyUser(user.user.hashedId, 'falukantUpdateStatus', {});
return { success: true }; return { success: true };
} }

View File

@@ -21,7 +21,7 @@
</thead> </thead>
<tbody> <tbody>
<tr v-for="(entry, index) in moneyHistory.data" :key="index"> <tr v-for="(entry, index) in moneyHistory.data" :key="index">
<td>{{ $t(`falukant.moneyHistory.activities.${entry.activity}`) }}</td> <td>{{ translateActivity(entry.activity) }}</td>
<td>{{ entry.moneyBefore }}</td> <td>{{ entry.moneyBefore }}</td>
<td>{{ entry.moneyAfter }}</td> <td>{{ entry.moneyAfter }}</td>
<td>{{ entry.changeValue }}</td> <td>{{ entry.changeValue }}</td>
@@ -79,6 +79,19 @@ export default {
console.error('Error fetching money history:', error); console.error('Error fetching money history:', error);
} }
}, },
translateActivity(activity) {
// Handle nested keys like "health.pill" -> "health.pill"
const key = `falukant.moneyHistory.activities.${activity}`;
const translation = this.$t(key);
// If translation is the same as key, try nested structure
if (translation === key && activity.includes('.')) {
const parts = activity.split('.');
const nestedKey = `falukant.moneyHistory.activities.${parts[0]}.${parts[1]}`;
const nestedTranslation = this.$t(nestedKey);
return nestedTranslation !== nestedKey ? nestedTranslation : activity;
}
return translation !== key ? translation : activity;
},
}, },
}; };
</script> </script>