aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r--server/models/utils.ts11
1 files changed, 7 insertions, 4 deletions
diff --git a/server/models/utils.ts b/server/models/utils.ts
index ec51c66bf..83b2b8f03 100644
--- a/server/models/utils.ts
+++ b/server/models/utils.ts
@@ -1,5 +1,4 @@
1import { literal, Op, OrderItem } from 'sequelize' 1import { literal, Op, OrderItem, Sequelize } from 'sequelize'
2import { Model, Sequelize } from 'sequelize-typescript'
3import { Col } from 'sequelize/types/lib/utils' 2import { Col } from 'sequelize/types/lib/utils'
4import validator from 'validator' 3import validator from 'validator'
5 4
@@ -103,6 +102,10 @@ function getFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]):
103} 102}
104 103
105function isOutdated (model: { createdAt: Date, updatedAt: Date }, refreshInterval: number) { 104function isOutdated (model: { createdAt: Date, updatedAt: Date }, refreshInterval: number) {
105 if (!model.createdAt || !model.updatedAt) {
106 throw new Error('Miss createdAt & updatedAt attribuets to model')
107 }
108
106 const now = Date.now() 109 const now = Date.now()
107 const createdAtTime = model.createdAt.getTime() 110 const createdAtTime = model.createdAt.getTime()
108 const updatedAtTime = model.updatedAt.getTime() 111 const updatedAtTime = model.updatedAt.getTime()
@@ -195,11 +198,11 @@ function parseAggregateResult (result: any) {
195 return total 198 return total
196} 199}
197 200
198const createSafeIn = (model: typeof Model, stringArr: (string | number)[]) => { 201function createSafeIn (sequelize: Sequelize, stringArr: (string | number)[]) {
199 return stringArr.map(t => { 202 return stringArr.map(t => {
200 return t === null 203 return t === null
201 ? null 204 ? null
202 : model.sequelize.escape('' + t) 205 : sequelize.escape('' + t)
203 }).join(', ') 206 }).join(', ')
204} 207}
205 208