Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function modelToJsonApi(model: IJsonapiModel): IRecord {
const staticModel = model.constructor as typeof PureModel;
const attributes: IDictionary = modelToJSON(model);
const useAutogenerated: boolean = staticModel['useAutogeneratedIds'];
const isPersisted = isModelPersisted(model);
const data: IRecord = {
attributes,
id: (isPersisted || useAutogenerated) ? getModelId(model) : undefined,
type: getModelType(model) as string,
};
const refs = getModelMetaKey(model, 'refs');
Object.keys(refs).forEach((key) => {
data.relationships = data.relationships || { };
const refIds = getRefId(model, key);
let rel: IDefinition|Array|undefined;