generators/app/templates/server/lib/controllers/param.controller.js
function (req, res, next, id) {
    var self = this;

    // check if a custom id is used, when not only process a valid object id
    if (this.mongoId && !ObjectID.isValid(id)) {
      res.badRequest();
      return next();
    }

    // attach the document as this.paramName to the request
    this.model.findOne({'_id': id}, function (err, doc) {
      if (err) {
        return next(err);
      }

      if (!doc) {
        res.notFound();
        return next('route');
      }

      req[self.paramName] = doc;
      return next();
    });
  }
function (req, res, next, id) {
    var self = this;

    // check if a custom id is used, when not only process a valid object id
    if (this.mongoId && !ObjectID.isValid(id)) {
      res.badRequest();
      return next();
    }

    // attach the document as this.paramName to the request
    this.model.findOne({'_id': id}, function (err, doc) {
      if (err) {
        return next(err);
      }

      if (!doc) {
        res.notFound();
        return next('route');
      }

      req[self.paramName] = doc;
      return next();
    });
  }
function ( req , res , next , id ) { var self = this ; // check if a custom id is used, when not only process a valid object id if ( this . mongoId && ! ObjectID . isValid ( id ) ) { res . badRequest ( ) ; return next ( ) ; } // attach the document as this.paramName to the request this . model . findOne ( { '_id' : id } , function ( err , doc ) { if ( err ) { return next ( err ) ; } if ( ! doc ) { res . notFound ( ) ; return next ( 'route' ) ; } req [ self . paramName ] = doc ; return next ( ) ; } ) ; }
Register the default id parameter for route requests.
Add a property to the current request which is the
document returned by the controller Model for the param configures
paramter name available in the processed request.
@param {http.IncomingMessage} req - The request message object
@param {http.ServerResponse} res - The outgoing response object
@param next {function} - The next handler function to call when done
@param id {String} - The id parameter parsed from the current request
@returns {function} This function sets a status of 400 for malformed MongoDB
id's and a status of 404 if no document has been found for the passed
parameter value. Calls the passed next function when done.
Register the default id parameter for route requests . Add a property to the current request which is the document returned by the controller Model for the param configures paramter name available in the processed request .