Skip to content

Commit

Permalink
utils: Use sort instead of sortBy
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac committed Feb 5, 2018
1 parent baca56f commit a8f56eb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports.oid = (id) => new ObjectID(id)
exports.findValidation = {
limit: Joi.number().integer().min(1).max(conf.mono.mongodb.findLimitMax).optional(),
offset: Joi.number().integer().min(0).optional(),
sortBy: Joi.string().replace(/\s/g, '').optional(),
sort: Joi.string().replace(/\s/g, '').optional(),
fields: Joi.string().replace(/\s/g, '').optional()
}

Expand All @@ -30,8 +30,8 @@ exports.getFindOptions = (query) => {
// Fields (?fields=name,ean)
if (query.fields) query.fields.split(',').filter((_) => _).forEach((field) => options.fields[field] = 1)
// Sort (?sort=position:asc)
if (query.sortBy) {
query.sortBy.split(',').filter((_) => _).forEach((sort) => {
if (query.sort) {
query.sort.split(',').filter((_) => _).forEach((sort) => {
const [key, order] = sort.split(':')
options.sort[key] = (order === 'desc' ? -1 : 1)
})
Expand Down

0 comments on commit a8f56eb

Please sign in to comment.