sarala-json-api-data-formatter
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -85,2 +85,4 @@ 'use strict'; | ||
value: function deserializeOne(data) { | ||
var _this = this; | ||
var formatted = {}; | ||
@@ -98,6 +100,4 @@ formatted.id = data.id; | ||
var thiss = this; | ||
_lodash2.default.forOwn(data.attributes, function (value, key) { | ||
if (thiss.shouldIncludeField(data.type, key)) { | ||
if (_this.shouldIncludeField(data.type, key)) { | ||
formatted[key] = value; | ||
@@ -118,3 +118,3 @@ } | ||
relationship.data = this.resolveRelationCollection(data.relationships[key].data); | ||
} else { | ||
} else if (data.relationships[key].data) { | ||
relationship.data = this.resolveRelation(data.relationships[key].data); | ||
@@ -133,7 +133,8 @@ } | ||
value: function deserializeCollection(data) { | ||
var thiss = this; | ||
var _this2 = this; | ||
data.data_collection = true; | ||
data.data = _lodash2.default.map(data.data, function (item) { | ||
return thiss.deserializeOne(item); | ||
return _this2.deserializeOne(item); | ||
}); | ||
@@ -151,6 +152,6 @@ | ||
value: function resolveRelationCollection(relations) { | ||
var _this = this; | ||
var _this3 = this; | ||
return _lodash2.default.map(relations, function (relation) { | ||
return _this.resolveRelation(relation); | ||
return _this3.resolveRelation(relation); | ||
}); | ||
@@ -196,2 +197,4 @@ } | ||
value: function serializeOne(data) { | ||
var _this4 = this; | ||
var serialized = { | ||
@@ -207,13 +210,11 @@ attributes: {}, | ||
var thiss = this; | ||
if (data.hasOwnProperty('relationships')) { | ||
_lodash2.default.forEach(data.relationships, function (relationship) { | ||
if (thiss.shouldIncludeRelation(relationship)) { | ||
var relationshipData = thiss.mapAndKillProps(data[relationship], {}, ['links', 'meta']).to; | ||
if (_this4.shouldIncludeRelation(relationship)) { | ||
var relationshipData = _this4.mapAndKillProps(data[relationship], {}, ['links', 'meta']).to; | ||
if (thiss.isSerializeableCollection(data[relationship])) { | ||
relationshipData.data = thiss.serializeRelationshipCollection(data[relationship].data); | ||
if (_this4.isSerializeableCollection(data[relationship])) { | ||
relationshipData.data = _this4.serializeRelationshipCollection(data[relationship].data); | ||
} else { | ||
relationshipData.data = thiss.serializeRelationship(data[relationship].data); | ||
relationshipData.data = _this4.serializeRelationship(data[relationship].data); | ||
} | ||
@@ -231,3 +232,3 @@ | ||
_lodash2.default.forOwn(data, function (value, key) { | ||
if (thiss.shouldIncludeField(serialized.type, key)) { | ||
if (_this4.shouldIncludeField(serialized.type, key)) { | ||
serialized.attributes[key] = value; | ||
@@ -246,3 +247,3 @@ } | ||
value: function serializeCollection(data) { | ||
var _this2 = this; | ||
var _this5 = this; | ||
@@ -255,3 +256,3 @@ var mapAndKilled = this.mapAndKillProps(data, {}, ['links', 'meta']); | ||
serialized.data = _lodash2.default.map(data.data, function (item) { | ||
return _this2.serializeOne(item); | ||
return _this5.serializeOne(item); | ||
}); | ||
@@ -272,6 +273,6 @@ | ||
value: function serializeRelationshipCollection(data) { | ||
var thiss = this; | ||
var _this6 = this; | ||
return _lodash2.default.map(data, function (item) { | ||
return thiss.serializeRelationship(item); | ||
return _this6.serializeRelationship(item); | ||
}); | ||
@@ -282,5 +283,3 @@ } | ||
value: function addToIncludes(data) { | ||
var thiss = this; | ||
if (_lodash2.default.isUndefined(_lodash2.default.find(thiss.includedData, { id: data.id, type: data.type }))) { | ||
if (_lodash2.default.isUndefined(_lodash2.default.find(this.includedData, { id: data.id, type: data.type }))) { | ||
this.includedData.push(data); | ||
@@ -287,0 +286,0 @@ } |
{ | ||
"name": "sarala-json-api-data-formatter", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Simple and fluent framework agnostic javascript library to transform standard JSON API responses to simple JSON objects and vice versa.", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
87931
1944