Skip to main content

List

List operation executes hook methods in the following sequence:

HookParametersDescription
docPermissions
  1. Mongoose document / plain document object
  2. global permissions
  • skips if option includePermissions set to false
  • called after Mongoose execute the query
  • runs on each document
decorate
  1. plain document object
  2. global permissions
  • runs on each document object
decorateAll
  1. plain document objects
  2. global permissions
  • runs on set of document objects

Configuration Example

modelRouter.docPermissions('list', function (docOrObject, globalPermissions) {
const isMe = String(docOrObject._id) === String(this.user._id);

return {
canEdit: globalPermissions.isAdmin || isMe,
};
});

modelRouter.decorate('list', function (docObject, globalPermissions) {
docObject.decoratedBy = 'egose';
return docObject;
});

modelRouter.decorateAll(function (docObjects, globalPermissions) {
const filtered = docObjects.filter((doc) => doc.public);
return filtered;
});