Created
April 30, 2013 14:18
-
-
Save johnsmith17th/5489033 to your computer and use it in GitHub Desktop.
Get sorting of query.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get sorting of query. | |
* | |
* @param {HttpRequest} req | |
* @param {Object} options | |
* - {Boolean} [customizable] | |
* whether the sorting is customizable | |
* i.e. can be pass from query string with the key $sort | |
* e.g. $sort=id,-key | |
* - {String} [defaults] | |
* defined default sorting of query | |
* e.g. 'id -key' | |
* @returns {String} sorting part for query | |
*/ | |
function __sorting(req, options) { | |
var result = null, | |
opt = options || {}; | |
// customizable | |
if (opt.customizable) { | |
result = utils.param(req, '$sort', function(value) { | |
return value ? value.replace(/\,/g, ' ') : null; | |
}); | |
}; | |
// default | |
if (!result && opt.defaults) { | |
result = opt.defaults; | |
}; | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment