baucis-decorator-update

1.0.1 • Public • Published

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;

Package Sidebar

Install

npm i baucis-decorator-update

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • timbur