Added support for multiple fields sorting (#512)

This commit is contained in:
Gabriel Medina
2017-05-09 05:56:38 -05:00
committed by typicode
parent 5ee5640ef7
commit fc90f4a19d
3 changed files with 43 additions and 8 deletions

View File

@ -144,14 +144,18 @@ module.exports = (db, name) => {
// Sort
if (_sort) {
_order = _order || 'ASC'
chain = chain.sortBy(function (element) {
return _.get(element, _sort)
})
if (_order === 'DESC') {
chain = chain.reverse()
if (_sort.match(/,/)) {
const _sortSet = _sort.split(/,/)
const _orderSet = _order.split(/,/)
chain = chain.orderBy(_sortSet, _orderSet)
} else {
_order = _order || 'ASC'
chain = chain.sortBy(function (element) {
return _.get(element, _sort)
})
if (_order === 'DESC') {
chain = chain.reverse()
}
}
}