Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Object.keys(data.relationships).forEach((key) => {
const ref = (data.relationships as IDictionary)[key];
if (ref && 'data' in ref && ref.data) {
if ((!(ref.data instanceof Array) || ref.data.length > 0)) {
rawData[key] = mapItems(ref.data, (item: IDefinition) => item.id);
if (!classRefs || !(key in classRefs)) {
refs[key] = {
model: ref.data instanceof Array ? ref.data[0].type : ref.data.type,
type: ref.data instanceof Array ? ReferenceType.TO_MANY : ReferenceType.TO_ONE,
};
}
} else {
rawData[key] = [];
}
}
if (ref && 'links' in ref) {
refLinks[key] = ref.links;
}
if (ref && 'meta' in ref) {
refMeta[key] = ref.meta;
}
rawData[META_FIELD].fields.push(...Object.keys(refs));
});