2016-08-16 22:31:45 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const utils = {
|
2016-12-11 21:50:51 +01:00
|
|
|
getSort
|
2016-08-16 22:31:45 +02:00
|
|
|
}
|
|
|
|
|
2016-12-11 21:50:51 +01:00
|
|
|
// Translate for example "-name" to [ 'name', 'DESC' ]
|
|
|
|
function getSort (value) {
|
|
|
|
let field
|
|
|
|
let direction
|
2016-08-16 22:31:45 +02:00
|
|
|
|
2016-12-11 21:50:51 +01:00
|
|
|
if (value.substring(0, 1) === '-') {
|
|
|
|
direction = 'DESC'
|
|
|
|
field = value.substring(1)
|
|
|
|
} else {
|
|
|
|
direction = 'ASC'
|
|
|
|
field = value
|
|
|
|
}
|
2016-08-16 22:31:45 +02:00
|
|
|
|
2016-12-11 21:50:51 +01:00
|
|
|
return [ field, direction ]
|
2016-08-16 22:31:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
module.exports = utils
|