]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/utils.ts
Remove any typing from server
[github/Chocobozzz/PeerTube.git] / server / models / utils.ts
1 // Translate for example "-name" to [ 'name', 'DESC' ]
2 function getSort (value: string) {
3 let field: string
4 let direction: 'ASC' | 'DESC'
5
6 if (value.substring(0, 1) === '-') {
7 direction = 'DESC'
8 field = value.substring(1)
9 } else {
10 direction = 'ASC'
11 field = value
12 }
13
14 return [ field, direction ]
15 }
16
17 function addMethodsToModel (model: any, classMethods: Function[], instanceMethods: Function[] = []) {
18 classMethods.forEach(m => model[m.name] = m)
19 instanceMethods.forEach(m => model.prototype[m.name] = m)
20 }
21
22 // ---------------------------------------------------------------------------
23
24 export {
25 addMethodsToModel,
26 getSort
27 }