baucis-decorator-update
v1.0.1
Published
Upon clients' updates, forces update of properties.
Downloads
3
Maintainers
Readme
baucis-decorator-update
Upon clients' updates, forces update of properties.
Install
npm install baucis-decorators baucis-decorator-update --save
Usage
Add the decorator and it will add the functionality to any properties containing an update
field as a function.
Example
controllers/Resource.js
var baucis = require('baucis');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.Types.ObjectId;
var ResourceProps = {};
ResourceProps.modified = {
type: Date,
default: Date.now,
required: true,
update: Date.now
};
ResourceProps.modifiedBy = {
type: ObjectId,
ref: 'User',
required: true,
update: function getUserId (req, res, next) {
return req.session.userId;
}
};
var ResourceSchema = new Schema(ResourceProps);
var ResourceModel = mongoose.model('Resource', ResourceSchema);
var ResourceController = baucis.rest('Resource');
var decorators = require('baucis-decorators');
decorators.add.call(ResourceController, [
'baucis-decorator-update'
]);
/**
* Expose controller.
*/
module.exports = ResourceController;