]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/utils.ts
Update server dependencies
[github/Chocobozzz/PeerTube.git] / server / models / utils.ts
index e27625bc862c8a20504b0e12c0224d9539c598b3..0950f5f32851667fae45516c13e645b2ac77eed1 100644 (file)
@@ -1,5 +1,5 @@
 import { literal, Op, OrderItem, Sequelize } from 'sequelize'
-import { Col } from 'sequelize/types/lib/utils'
+import { Col } from 'sequelize/types/utils'
 import validator from 'validator'
 
 type SortType = { sortModel: string, sortValue: string }
@@ -74,8 +74,8 @@ function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): Or
     finalField = field
   }
 
-  const firstSort = typeof finalField === 'string'
-    ? finalField.split('.').concat([ direction ]) as any // FIXME: sequelize typings
+  const firstSort: OrderItem = typeof finalField === 'string'
+    ? finalField.split('.').concat([ direction ]) as OrderItem
     : [ finalField, direction ]
 
   return [ firstSort, lastSort ]
@@ -84,7 +84,7 @@ function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): Or
 function getBlacklistSort (model: any, value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
   const [ firstSort ] = getSort(value)
 
-  if (model) return [ [ literal(`"${model}.${firstSort[0]}" ${firstSort[1]}`) ], lastSort ] as any[] // FIXME: typings
+  if (model) return [ [ literal(`"${model}.${firstSort[0]}" ${firstSort[1]}`) ], lastSort ] as OrderItem[]
   return [ firstSort, lastSort ]
 }
 
@@ -102,6 +102,10 @@ function getFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]):
 }
 
 function isOutdated (model: { createdAt: Date, updatedAt: Date }, refreshInterval: number) {
+  if (!model.createdAt || !model.updatedAt) {
+    throw new Error('Miss createdAt & updatedAt attribuets to model')
+  }
+
   const now = Date.now()
   const createdAtTime = model.createdAt.getTime()
   const updatedAtTime = model.updatedAt.getTime()
@@ -234,7 +238,8 @@ function searchAttribute (sourceField?: string, targetField?: string) {
 
   return {
     [targetField]: {
-      [Op.iLike]: `%${sourceField}%`
+      // FIXME: ts error
+      [Op.iLike as any]: `%${sourceField}%`
     }
   }
 }