Skip to content

Commit 9f8b5e9

Browse files
committed
Refactor sort
1 parent 13607b8 commit 9f8b5e9

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/server/router/plural.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,9 @@ module.exports = (db, name) => {
144144

145145
// Sort
146146
if (_sort) {
147-
if (_sort.match(/,/)) {
148-
const _sortSet = _sort.split(/,/)
149-
const _orderSet = _order.split(/,/)
150-
chain = chain.orderBy(_sortSet, _orderSet)
151-
} else {
152-
_order = _order || 'ASC'
153-
chain = chain.sortBy(function (element) {
154-
return _.get(element, _sort)
155-
})
156-
if (_order === 'DESC') {
157-
chain = chain.reverse()
158-
}
159-
}
147+
const _sortSet = _sort.split(',')
148+
const _orderSet = (_order || '').split(',').map(s => s.toLowerCase())
149+
chain = chain.orderBy(_sortSet, _orderSet)
160150
}
161151

162152
// Slice result

0 commit comments

Comments
 (0)