]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/utils.ts
Don't cache torrent files
[github/Chocobozzz/PeerTube.git] / server / models / utils.ts
index 601811913d5d24dde4aedcd7486882638ab3ef86..1bf61d2a693021aff86a88732587dfabe3ccd87b 100644 (file)
@@ -1,7 +1,7 @@
 // Translate for example "-name" to [ 'name', 'DESC' ]
-function getSort (value) {
-  let field
-  let direction
+function getSort (value: string) {
+  let field: string
+  let direction: 'ASC' | 'DESC'
 
   if (value.substring(0, 1) === '-') {
     direction = 'DESC'
@@ -14,8 +14,22 @@ function getSort (value) {
   return [ field, direction ]
 }
 
+function addMethodsToModel (model: any, classMethods: Function[], instanceMethods: Function[] = []) {
+  classMethods.forEach(m => model[m.name] = m)
+  instanceMethods.forEach(m => model.prototype[m.name] = m)
+}
+
+function getSortOnModel (model: any, value: string) {
+  let sort = getSort(value)
+
+  if (model) return [ { model: model }, sort[0], sort[1] ]
+  return sort
+}
+
 // ---------------------------------------------------------------------------
 
 export {
-  getSort
+  addMethodsToModel,
+  getSort,
+  getSortOnModel
 }