mirror of
https://github.com/typicode/json-server.git
synced 2025-08-01 06:34:02 +08:00
Refactor sort
This commit is contained in:
@ -144,19 +144,9 @@ module.exports = (db, name) => {
|
|||||||
|
|
||||||
// Sort
|
// Sort
|
||||||
if (_sort) {
|
if (_sort) {
|
||||||
if (_sort.match(/,/)) {
|
const _sortSet = _sort.split(',')
|
||||||
const _sortSet = _sort.split(/,/)
|
const _orderSet = (_order || '').split(',').map(s => s.toLowerCase())
|
||||||
const _orderSet = _order.split(/,/)
|
|
||||||
chain = chain.orderBy(_sortSet, _orderSet)
|
chain = chain.orderBy(_sortSet, _orderSet)
|
||||||
} else {
|
|
||||||
_order = _order || 'ASC'
|
|
||||||
chain = chain.sortBy(function (element) {
|
|
||||||
return _.get(element, _sort)
|
|
||||||
})
|
|
||||||
if (_order === 'DESC') {
|
|
||||||
chain = chain.reverse()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slice result
|
// Slice result
|
||||||
|
Reference in New Issue
Block a user