Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions projects/angular2-jsonapi/src/models/json-api.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,23 @@ import { HttpHeaders } from '@angular/common/http';
// tslint:disable-next-line:variable-name
const AttributeMetadataIndex: string = AttributeMetadata as any;

const parseRelationshipLinks = relationships => {
const result = {};
const linksMapper = ({ links }, key) => {
if (links) {
result[key] = { links };
}
};

_.forEach(relationships || {}, linksMapper);

return result;
};

export class JsonApiModel {
id: string;
public modelInitialization = false;
public relationshipLinks = {};

[key: string]: any;

Expand All @@ -28,6 +42,7 @@ export class JsonApiModel {
if (data) {
this.modelInitialization = true;
this.id = data.id;
this.relationshipLinks = parseRelationshipLinks(data.relationships);
Object.assign(this, data.attributes);
this.modelInitialization = false;
}
Expand Down