2016-12-11 14:50:51 -06:00
|
|
|
// Translate for example "-name" to [ 'name', 'DESC' ]
|
|
|
|
function getSort (value) {
|
|
|
|
let field
|
|
|
|
let direction
|
2016-08-16 15:31:45 -05:00
|
|
|
|
2016-12-11 14:50:51 -06:00
|
|
|
if (value.substring(0, 1) === '-') {
|
|
|
|
direction = 'DESC'
|
|
|
|
field = value.substring(1)
|
|
|
|
} else {
|
|
|
|
direction = 'ASC'
|
|
|
|
field = value
|
|
|
|
}
|
2016-08-16 15:31:45 -05:00
|
|
|
|
2016-12-11 14:50:51 -06:00
|
|
|
return [ field, direction ]
|
2016-08-16 15:31:45 -05:00
|
|
|
}
|
|
|
|
|
2017-05-22 13:58:25 -05:00
|
|
|
function addMethodsToModel (model: any, classMethods: Function[], instanceMethods: Function[] = []) {
|
|
|
|
classMethods.forEach(m => model[m.name] = m)
|
|
|
|
instanceMethods.forEach(m => model.prototype[m.name] = m)
|
|
|
|
}
|
|
|
|
|
2016-08-16 15:31:45 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-05-15 15:22:03 -05:00
|
|
|
export {
|
2017-05-22 13:58:25 -05:00
|
|
|
addMethodsToModel,
|
2017-05-15 15:22:03 -05:00
|
|
|
getSort
|
|
|
|
}
|