Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private __addRecord(obj: IRecord): IJsonapiModel {
const staticCollection = this.constructor as typeof Collection;
const {type, id} = obj;
let record: IJsonapiModel = this.find(type, id) as IJsonapiModel;
const flattened: IRawModel = flattenModel(obj);
if (record) {
updateModel(record, flattened);
} else if (staticCollection.types.filter((item) => item.type === obj.type).length) {
record = this.add(flattened, obj.type) as IJsonapiModel;
} else {
record = this.add(new Model(flattened));
}
return record;
}