baucis-decorator-required
v1.0.1
Published
Changes the `required` validator to only be active when creating resources.
Downloads
2
Maintainers
Readme
baucis-decorator-required
Changes the required
validator to only be active when creating resources.
Install
npm install baucis-decorators baucis-decorator-required --save
Usage
Add the decorator and it will replace the functionality for any required
properties.
Example
controllers/Resource.js
var baucis = require('baucis');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.Types.ObjectId;
var ResourceProps = {};
ResourceProps.created = {
type: Date,
default: Date.now,
required: true,
reserved: true
};
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-required'
]);
/**
* Expose controller.
*/
module.exports = ResourceController;