Normalisiere eingehende API-Daten: Akzeptiere sowohl camelCase als auch snake_case für die Eigenschaften des Falukant-Datenobjekts.

This commit is contained in:
Torsten Schulz (local)
2026-02-14 16:41:14 +01:00
parent cc80081280
commit af4e5de1ad

View File

@@ -24,8 +24,31 @@ export default {
},
computed: {
falukantData() {
const d = this.data;
if (d && typeof d === 'object' && 'characterName' in d && 'money' in d) return d;
// normalize incoming API payload: accept both camelCase and snake_case
const raw = this.data;
if (!raw || typeof raw !== 'object') return null;
const pick = (obj, camel, snake) => {
if (camel in obj && obj[camel] !== undefined) return obj[camel];
if (snake in obj && obj[snake] !== undefined) return obj[snake];
return undefined;
};
const normalized = {
characterName: pick(raw, 'characterName', 'character_name') ?? pick(raw, 'nameWithoutTitle', 'name_without_title'),
nameWithoutTitle: pick(raw, 'nameWithoutTitle', 'name_without_title'),
titleLabelTr: pick(raw, 'titleLabelTr', 'title_label_tr'),
gender: pick(raw, 'gender', 'gender'),
age: pick(raw, 'age', 'age'),
money: pick(raw, 'money', 'money'),
unreadNotificationsCount: pick(raw, 'unreadNotificationsCount', 'unread_notifications_count'),
childrenCount: pick(raw, 'childrenCount', 'children_count'),
// keep all original keys as fallback for any other usage
...raw
};
// sanity: require at least a name and money
if ((normalized.characterName || normalized.nameWithoutTitle) && (normalized.money !== undefined)) return normalized;
return null;
},
falukantDisplayName() {