jsonapi-renderer
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "jsonapi-renderer", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Helper for generating jsonapi compliant output from models", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -12,3 +12,7 @@ 'use strict'; | ||
Render.prototype.shouldRenderField = function(model, name, descriptor, fieldsRequested) { | ||
Render.prototype.shouldRenderField = function(model, name, descriptor, fieldsRequested, fieldsAllowed) { | ||
if (!_.isUndefined(fieldsAllowed) && !_.includes(fieldsAllowed, name)) { | ||
return false; | ||
} | ||
if (descriptor.valid && !descriptor.valid.call(model)) { | ||
@@ -33,7 +37,6 @@ return false; | ||
Render.prototype.extractRenderedFields = function(model, fields, fieldsRequested) { | ||
var filtered = _.pick(fields, function(fieldDescriptor, name) { | ||
return this.shouldRenderField(model, name, fieldDescriptor, fieldsRequested); | ||
Render.prototype.extractRenderedFields = function(model, fields, fieldsRequested, fieldsAllowed) { | ||
return _.pick(fields, function(fieldDescriptor, name) { | ||
return this.shouldRenderField(model, name, fieldDescriptor, fieldsRequested, fieldsAllowed); | ||
}, this); | ||
return filtered; | ||
}; | ||
@@ -180,2 +183,3 @@ | ||
var fieldsRequested = options.fields[definition.type]; | ||
var fieldsAllowed = options.fieldsAllowed && options.fieldsAllowed[definition.type]; | ||
@@ -185,3 +189,3 @@ var promises = []; | ||
promises.push(this.getAllAttributes(model, definition).then(function(allAttributes) { | ||
var attributesToRender = this.extractRenderedFields(model, allAttributes, fieldsRequested); | ||
var attributesToRender = this.extractRenderedFields(model, allAttributes, fieldsRequested, fieldsAllowed); | ||
if (_.keys(attributesToRender).length > 0) { | ||
@@ -199,3 +203,3 @@ data.attributes = {}; | ||
promises.push(this.getAllRelationships(model, definition).then(function(allRelationships) { | ||
var relationshipsToRender = this.extractRenderedFields(model, allRelationships, fieldsRequested); | ||
var relationshipsToRender = this.extractRenderedFields(model, allRelationships, fieldsRequested, fieldsAllowed); | ||
if (_.keys(relationshipsToRender).length > 0) { | ||
@@ -202,0 +206,0 @@ data.relationships = {}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17695
376