Normalisiere eingehende API-Daten: Akzeptiere sowohl camelCase als auch snake_case für die Eigenschaften des Falukant-Datenobjekts.
This commit is contained in:
@@ -24,8 +24,31 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
falukantData() {
|
falukantData() {
|
||||||
const d = this.data;
|
// normalize incoming API payload: accept both camelCase and snake_case
|
||||||
if (d && typeof d === 'object' && 'characterName' in d && 'money' in d) return d;
|
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;
|
return null;
|
||||||
},
|
},
|
||||||
falukantDisplayName() {
|
falukantDisplayName() {
|
||||||
|
|||||||
Reference in New Issue
Block a user