baucis-decorator-once

1.0.1 • Public • Published

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;

Package Sidebar

Install

npm i baucis-decorator-once

Weekly Downloads

3

Version

1.0.1

License

MIT

Last publish

Collaborators

  • timbur