X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Futils.ts;h=83b2b8f03cba2ac31607088073e5e449cacbd910;hb=d4a8e7a65f97bb3257facc13e1ae8ffdbad61ddb;hp=5337ae75dc38f924b3a89974e9b28c930a735eb4;hpb=9d6b9d10ef8cbef39e89bc709285abffb0d8caa1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/utils.ts b/server/models/utils.ts index 5337ae75d..83b2b8f03 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -1,5 +1,4 @@ -import { literal, Op, OrderItem } from 'sequelize' -import { Model, Sequelize } from 'sequelize-typescript' +import { literal, Op, OrderItem, Sequelize } from 'sequelize' import { Col } from 'sequelize/types/lib/utils' import validator from 'validator' @@ -54,6 +53,14 @@ function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): Or [ Sequelize.col('VideoModel.views'), direction ], + lastSort + ] + } else if (field === 'publishedAt') { + return [ + [ 'ScheduleVideoUpdate', 'updateAt', direction + ' NULLS LAST' ], + + [ Sequelize.col('VideoModel.publishedAt'), direction ], + lastSort ] } @@ -95,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() @@ -187,11 +198,11 @@ function parseAggregateResult (result: any) { return total } -const createSafeIn = (model: typeof Model, stringArr: (string | number)[]) => { +function createSafeIn (sequelize: Sequelize, stringArr: (string | number)[]) { return stringArr.map(t => { return t === null ? null - : model.sequelize.escape('' + t) + : sequelize.escape('' + t) }).join(', ') }