Skip to main content

Read

Read 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
decorate
  1. plain document object
  2. global permissions
  • runs on each document object

Configuration Example

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

return {
'edit.name': globalPermissions.isAdmin || isMe,
'edit.role': globalPermissions.isAdmin,
};
});

modelRouter.decorate('read', function (docObject, globalPermissions) {
docObject.timestamp = new Date();
return docObject;
});