From 198de237355869584225fb52490e3ce3623e5f4b Mon Sep 17 00:00:00 2001 From: Maksym Pugach Date: Mon, 23 Dec 2019 18:17:23 +0200 Subject: [PATCH] expose relationship links --- .../angular2-jsonapi/src/models/json-api.model.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/projects/angular2-jsonapi/src/models/json-api.model.ts b/projects/angular2-jsonapi/src/models/json-api.model.ts index 629381ba..43ba8989 100644 --- a/projects/angular2-jsonapi/src/models/json-api.model.ts +++ b/projects/angular2-jsonapi/src/models/json-api.model.ts @@ -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; @@ -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; }