diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/video-query-builder.ts | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/server/models/video/video-query-builder.ts b/server/models/video/video-query-builder.ts index 61f628c06..655abf198 100644 --- a/server/models/video/video-query-builder.ts +++ b/server/models/video/video-query-builder.ts | |||
@@ -3,6 +3,7 @@ import { buildDirectionAndField, createSafeIn } from '@server/models/utils' | |||
3 | import { Model } from 'sequelize-typescript' | 3 | import { Model } from 'sequelize-typescript' |
4 | import { MUserAccountId, MUserId } from '@server/typings/models' | 4 | import { MUserAccountId, MUserId } from '@server/typings/models' |
5 | import validator from 'validator' | 5 | import validator from 'validator' |
6 | import { exists } from '@server/helpers/custom-validators/misc' | ||
6 | 7 | ||
7 | export type BuildVideosQueryOptions = { | 8 | export type BuildVideosQueryOptions = { |
8 | attributes?: string[] | 9 | attributes?: string[] |
@@ -312,14 +313,21 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions) | |||
312 | let suffix = '' | 313 | let suffix = '' |
313 | let order = '' | 314 | let order = '' |
314 | if (options.isCount !== true) { | 315 | if (options.isCount !== true) { |
315 | const count = parseInt(options.count + '', 10) | ||
316 | const start = parseInt(options.start + '', 10) | ||
317 | 316 | ||
318 | order = buildOrder(model, options.sort) | 317 | if (exists(options.sort)) { |
318 | order = buildOrder(model, options.sort) | ||
319 | suffix += `${order} ` | ||
320 | } | ||
321 | |||
322 | if (exists(options.count)) { | ||
323 | const count = parseInt(options.count + '', 10) | ||
324 | suffix += `LIMIT ${count} ` | ||
325 | } | ||
319 | 326 | ||
320 | suffix = order + ' ' + | 327 | if (exists(options.start)) { |
321 | 'LIMIT ' + count + ' ' + | 328 | const start = parseInt(options.start + '', 10) |
322 | 'OFFSET ' + start | 329 | suffix += `OFFSET ${start} ` |
330 | } | ||
323 | } | 331 | } |
324 | 332 | ||
325 | const cteString = cte.length !== 0 | 333 | const cteString = cte.length !== 0 |