Update
Update
operation executes hook methods in the following sequence:
Hook | Parameters | Description |
---|---|---|
docPermissions |
|
|
validate |
| |
prepare |
| |
transform |
|
|
docPermissions |
|
|
decorate |
|
Configuration Example
modelRouter.validate('update', function (dataObject, globalPermissions) {
return true;
});
modelRouter.prepare('update', function (dataObject, globalPermissions) {
dataObject.name = dataObject.name.trim();
return dataObject;
});
modelRouter.transform(function (doc, globalPermissions) {
return doc;
});
modelRouter.docPermissions('update', function (doc, globalPermissions) {
const isMe = String(doc._id) === String(this.user._id);
return {
'edit.name': globalPermissions.isAdmin || isMe,
'edit.role': globalPermissions.isAdmin,
};
});
modelRouter.decorate('update', function (docObject, globalPermissions) {
docObject.decoratedBy = 'egose';
return docObject;
});