aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-query-builder.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video-query-builder.ts')
-rw-r--r--server/models/video/video-query-builder.ts20
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'
3import { Model } from 'sequelize-typescript' 3import { Model } from 'sequelize-typescript'
4import { MUserAccountId, MUserId } from '@server/typings/models' 4import { MUserAccountId, MUserId } from '@server/typings/models'
5import validator from 'validator' 5import validator from 'validator'
6import { exists } from '@server/helpers/custom-validators/misc'
6 7
7export type BuildVideosQueryOptions = { 8export 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