diff options
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r-- | server/models/utils.ts | 11 |
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 @@ | |||
1 | import { literal, Op, OrderItem } from 'sequelize' | 1 | import { literal, Op, OrderItem, Sequelize } from 'sequelize' |
2 | import { Model, Sequelize } from 'sequelize-typescript' | ||
3 | import { Col } from 'sequelize/types/lib/utils' | 2 | import { Col } from 'sequelize/types/lib/utils' |
4 | import validator from 'validator' | 3 | import validator from 'validator' |
5 | 4 | ||
@@ -103,6 +102,10 @@ function getFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): | |||
103 | } | 102 | } |
104 | 103 | ||
105 | function isOutdated (model: { createdAt: Date, updatedAt: Date }, refreshInterval: number) { | 104 | function 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 | ||
198 | const createSafeIn = (model: typeof Model, stringArr: (string | number)[]) => { | 201 | function 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 | ||