Skip to content

Commit

Permalink
adding attributes option to resource creation for specifying attribut…
Browse files Browse the repository at this point in the history
…es to be included
  • Loading branch information
philotas committed Oct 8, 2015
1 parent 470abb2 commit 5667765
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/Controllers/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ List.prototype.fetch = function(req, res, context) {
options.include = include;
}

if(this.resource.attributes.length)
options.attributes = this.resource.attributes;

var searchParam = this.resource.search.param;
if (_.has(req.query, searchParam)) {
var search = [];
Expand Down
3 changes: 3 additions & 0 deletions lib/Controllers/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Read.prototype.fetch = function(req, res, context) {
}
}

if(this.resource.attributes.length)
options.attributes = this.resource.attributes;

return model
.find(options)
.then(function(instance) {
Expand Down
4 changes: 3 additions & 1 deletion lib/Resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var Resource = function(options) {
actions: ['create', 'read', 'update', 'delete', 'list'],
pagination: true,
reloadInstances: true,
include: []
include: [],
attributes: []
});

_.defaultsDeep(options, {
Expand All @@ -30,6 +31,7 @@ var Resource = function(options) {
this.include = options.include.map(function(include) {
return include instanceof options.sequelize.Model ? { model: include } : include;
});
this.attributes = options.attributes;

this.actions = options.actions;
this.endpoints = {
Expand Down
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ var epilogue = {
search: options.search,
sort: options.sort,
reloadInstances: options.reloadInstances,
associations: options.associations
associations: options.associations,
attributes: options.attributes
});

return resource;
Expand Down

0 comments on commit 5667765

Please sign in to comment.