Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
refs.forEach((ref: string) => {
const items = (obj.relationships as IDictionary)[ref].data;
if (items instanceof Array && items.length < 1) {
// it's only possible to update items with one ore more refs. Early exit
return;
}
if (items && record) {
const models: Model|Array|IIdentifier|undefined|null = mapItems(
items,
(def: IDefinition) => this.find(def.type, def.id) || def.id,
);
const itemType: string = items instanceof Array ? items[0].type : items.type;
if (ref in record) {
record[ref] = models;
} else {
// @ts-ignore - Ignore until datx is updated
initModelRef(record, ref, {model: itemType, type: ReferenceType.TO_ONE_OR_MANY}, models);
}
}
});
}
private __iterateEntries(body: IResponse, fn: (item: Model) => Model) {
mapItems((body && body.included) || [], fn);
return mapItems((body && body.data) || [], fn);
}
private __iterateEntries(body: IResponse, fn: (item: Model) => Model) {
mapItems((body && body.included) || [], fn);
return mapItems((body && body.data) || [], fn);
}