lib/mock/query-resource.js
function queryResource (req, res, next, dataStore) {
  let resource = new Resource(req.path);

  dataStore.get(resource, (err, result) => {
    if (err) {
      next(err);
    }
    else if (!result) {
      let defaultValue = getDefaultValue(res);

      if (defaultValue === undefined) {
        util.debug("ERROR! 404 - %s %s does not exist", req.method, req.path);
        err = ono({ status: 404 }, "%s Not Found", resource.toString());
        next(err);
      }
      else {
        // There' a default value, so use it instead of sending a 404
        util.debug(
          "%s %s does not exist, but the response schema defines a fallback value.  So, using the fallback value",
          req.method, req.path
        );
        res.swagger.lastModified = new Date();
        res.body = defaultValue;
        next();
      }
    }
    else {
      res.swagger.lastModified = result.modifiedOn;

      // Set the response body (unless it's already been set by other middleware)
      res.body = res.body || result.data;
      next();
    }
  });
}
function queryResource (req, res, next, dataStore) {
  let resource = new Resource(req.path);

  dataStore.get(resource, (err, result) => {
    if (err) {
      next(err);
    }
    else if (!result) {
      let defaultValue = getDefaultValue(res);

      if (defaultValue === undefined) {
        util.debug("ERROR! 404 - %s %s does not exist", req.method, req.path);
        err = ono({ status: 404 }, "%s Not Found", resource.toString());
        next(err);
      }
      else {
        // There' a default value, so use it instead of sending a 404
        util.debug(
          "%s %s does not exist, but the response schema defines a fallback value.  So, using the fallback value",
          req.method, req.path
        );
        res.swagger.lastModified = new Date();
        res.body = defaultValue;
        next();
      }
    }
    else {
      res.swagger.lastModified = result.modifiedOn;

      // Set the response body (unless it's already been set by other middleware)
      res.body = res.body || result.data;
      next();
    }
  });
}
function queryResource ( req , res , next , dataStore ) { let resource = new Resource ( req . path ) ; dataStore . get ( resource , ( err , result ) => { if ( err ) { next ( err ) ; } else if ( ! result ) { let defaultValue = getDefaultValue ( res ) ; if ( defaultValue === undefined ) { util . debug ( "ERROR! 404 - %s %s does not exist" , req . method , req . path ) ; err = ono ( { status : 404 } , "%s Not Found" , resource . toString ( ) ) ; next ( err ) ; } else { // There' a default value, so use it instead of sending a 404 util . debug ( "%s %s does not exist, but the response schema defines a fallback value.  So, using the fallback value" , req . method , req . path ) ; res . swagger . lastModified = new Date ( ) ; res . body = defaultValue ; next ( ) ; } } else { res . swagger . lastModified = result . modifiedOn ; // Set the response body (unless it's already been set by other middleware) res . body = res . body || result . data ; next ( ) ; } } ) ; }
Returns the REST resource at the URL.
If there's no resource that matches the URL, then a 404 error is returned.

@param   {Request}   req
@param   {Response}  res
@param   {function}  next
@param   {DataStore} dataStore
Returns the REST resource at the URL . If there s no resource that matches the URL then a 404 error is returned .