lib/queryConfig.js
function QueryConfig (req, res, config) {
  var sort = req.query.sort
  var order = req.query.order
  var select = req.query.select
  var skip = req.query.skip
  var limit = req.query.limit
  var page = req.query.page
  var perPage = config.perPage || 10
  var idAttribute = config.idParam ? req.params[config.idParam] : req.params.idAttribute
  var query = config.query || {}
  var updateRef = config.updateRef
  var conditions = query.conditions || {}
  var options = query.options || {}
  var fields = query.fields || ''
  var subDoc = config.subDoc
  var data = req.body

  // sort order
  if (sort && (order === 'desc' || order === 'descending' || order === '-1')) {
    options.sort = '-' + sort
  }

  if (sort && (order === 'asc' || order === 'ascending' || order === '1')) {
    options.sort = sort
  }

  if (skip) {
    options.skip = skip
  }

  if (limit) {
    options.limit = limit
  }

  // pagination
  if (page) {
    options.skip = page * perPage
    options.limit = perPage
  }

  // to find unique record for update, remove and findOne
  if (idAttribute) {
    conditions[config.idAttribute || '_id'] = idAttribute
  }

  while (subDoc) {
    idAttribute = subDoc.idParam ? req.params[subDoc.idParam] : req.params.idAttribute
    if (idAttribute) {
      subDoc.conditions = {}
      subDoc.conditions[subDoc.idAttribute] = idAttribute
    }
    subDoc = subDoc.subDoc
  }

  if (select) {
    fields = select.replace(/,/g, ' ')
  }

  return {
    conditions: conditions,
    subDoc: config.subDoc,
    fields: fields,
    options: options,
    data: data,
    callback: callback(req, res, updateRef)
  }
}
function QueryConfig (req, res, config) {
  var sort = req.query.sort
  var order = req.query.order
  var select = req.query.select
  var skip = req.query.skip
  var limit = req.query.limit
  var page = req.query.page
  var perPage = config.perPage || 10
  var idAttribute = config.idParam ? req.params[config.idParam] : req.params.idAttribute
  var query = config.query || {}
  var updateRef = config.updateRef
  var conditions = query.conditions || {}
  var options = query.options || {}
  var fields = query.fields || ''
  var subDoc = config.subDoc
  var data = req.body

  // sort order
  if (sort && (order === 'desc' || order === 'descending' || order === '-1')) {
    options.sort = '-' + sort
  }

  if (sort && (order === 'asc' || order === 'ascending' || order === '1')) {
    options.sort = sort
  }

  if (skip) {
    options.skip = skip
  }

  if (limit) {
    options.limit = limit
  }

  // pagination
  if (page) {
    options.skip = page * perPage
    options.limit = perPage
  }

  // to find unique record for update, remove and findOne
  if (idAttribute) {
    conditions[config.idAttribute || '_id'] = idAttribute
  }

  while (subDoc) {
    idAttribute = subDoc.idParam ? req.params[subDoc.idParam] : req.params.idAttribute
    if (idAttribute) {
      subDoc.conditions = {}
      subDoc.conditions[subDoc.idAttribute] = idAttribute
    }
    subDoc = subDoc.subDoc
  }

  if (select) {
    fields = select.replace(/,/g, ' ')
  }

  return {
    conditions: conditions,
    subDoc: config.subDoc,
    fields: fields,
    options: options,
    data: data,
    callback: callback(req, res, updateRef)
  }
}
function QueryConfig ( req , res , config ) { var sort = req . query . sort var order = req . query . order var select = req . query . select var skip = req . query . skip var limit = req . query . limit var page = req . query . page var perPage = config . perPage || 10 var idAttribute = config . idParam ? req . params [ config . idParam ] : req . params . idAttribute var query = config . query || { } var updateRef = config . updateRef var conditions = query . conditions || { } var options = query . options || { } var fields = query . fields || '' var subDoc = config . subDoc var data = req . body // sort order if ( sort && ( order === 'desc' || order === 'descending' || order === '-1' ) ) { options . sort = '-' + sort } if ( sort && ( order === 'asc' || order === 'ascending' || order === '1' ) ) { options . sort = sort } if ( skip ) { options . skip = skip } if ( limit ) { options . limit = limit } // pagination if ( page ) { options . skip = page * perPage options . limit = perPage } // to find unique record for update, remove and findOne if ( idAttribute ) { conditions [ config . idAttribute || '_id' ] = idAttribute } while ( subDoc ) { idAttribute = subDoc . idParam ? req . params [ subDoc . idParam ] : req . params . idAttribute if ( idAttribute ) { subDoc . conditions = { } subDoc . conditions [ subDoc . idAttribute ] = idAttribute } subDoc = subDoc . subDoc } if ( select ) { fields = select . replace ( / , / g , ' ' ) } return { conditions : conditions , subDoc : config . subDoc , fields : fields , options : options , data : data , callback : callback ( req , res , updateRef ) } }
returns the process object with the passed data for pagination and sorting
returns the process object with the passed data for pagination and sorting