1
0
Fork 0
peertube/server/models/utils.ts

28 lines
627 B
TypeScript
Raw Normal View History

2016-12-11 15:50:51 -05:00
// Translate for example "-name" to [ 'name', 'DESC' ]
function getSort (value) {
let field
let direction
2016-08-16 16:31:45 -04:00
2016-12-11 15:50:51 -05:00
if (value.substring(0, 1) === '-') {
direction = 'DESC'
field = value.substring(1)
} else {
direction = 'ASC'
field = value
}
2016-08-16 16:31:45 -04:00
2016-12-11 15:50:51 -05:00
return [ field, direction ]
2016-08-16 16:31:45 -04:00
}
2017-05-22 14:58:25 -04: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 16:31:45 -04:00
// ---------------------------------------------------------------------------
2017-05-15 16:22:03 -04:00
export {
2017-05-22 14:58:25 -04:00
addMethodsToModel,
2017-05-15 16:22:03 -04:00
getSort
}