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