baucis-decorator-init

1.0.1 • Public • Published

baucis-decorator-init

Initializes certain properties upon creation of a resource. Different from default in that it is able to use the req object.

Install

npm install baucis-decorators baucis-decorator-init --save

Usage

Add the decorator and it will add the functionality to any properties containing an init 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.editors = {
  type: [{
    type: ObjectId,
    ref: 'User'
  }],
  init: function (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-init'
]);

/**
 * Expose controller.
 */
module.exports = ResourceController;

Package Sidebar

Install

npm i baucis-decorator-init

Weekly Downloads

2

Version

1.0.1

License

MIT

Last publish

Collaborators

  • timbur