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

28 lines
659 B
TypeScript
Raw Normal View History

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