baucis-decorator-once
v1.0.1
Published
Prevents clients from updating certain properties.
Downloads
2
Readme
baucis-decorator-once
Prevents clients from updating certain properties.
Install
npm install baucis-decorators baucis-decorator-once --save
Usage
Add the decorator and it will add the functionality to any properties containing a once
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.createdBy = {
type: ObjectId,
ref: 'User',
required: true,
once: 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-once'
]);
/**
* Expose controller.
*/
module.exports = ResourceController;