asDict args, handles multiple entities, values
parent
f738875905
commit
c77bb8a425
|
@ -8,14 +8,23 @@ export function listingAsOrdered(listing: ListingResult): OrderedListing {
|
||||||
.sort(([_, a], [__, b]) => a.attribute.localeCompare(b.attribute));
|
.sort(([_, a], [__, b]) => a.attribute.localeCompare(b.attribute));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function asDict(attributes: OrderedListing): {
|
export function asDict(attributes: IEntry[]) {
|
||||||
[key: string]: string;
|
const result = {} as { [key: string]: { [key: string]: unknown } };
|
||||||
} {
|
attributes.forEach((entry) => {
|
||||||
const result = {} as { [key: string]: string };
|
if (!result[entry.entity]) {
|
||||||
attributes
|
result[entry.entity] = {};
|
||||||
.map(([_, attribute]) => attribute)
|
}
|
||||||
.forEach((attribute) => {
|
if (result[entry.entity][entry.attribute]) {
|
||||||
result[attribute.attribute] = attribute.value.c;
|
if (!Array.isArray(result[entry.entity][entry.attribute])) {
|
||||||
});
|
result[entry.entity][entry.attribute] = [
|
||||||
|
result[entry.entity][entry.attribute],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
(result[entry.entity][entry.attribute] as unknown[]).push(entry.value.c);
|
||||||
|
} else {
|
||||||
|
result[entry.entity][entry.attribute] = entry.value.c;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue