diff options
author | Chocobozzz <me@florianbigard.com> | 2021-05-12 14:09:04 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-05-12 14:12:14 +0200 |
commit | 16c016e8b1d5ca46343d3363f9a49e24c5d7c944 (patch) | |
tree | 157dfa22ac95bd76a411aaf78e4df17152530e1c /server/models/video/video.ts | |
parent | 9a320a06b663a2e02c3156a07135f75f9e987b11 (diff) | |
download | PeerTube-16c016e8b1d5ca46343d3363f9a49e24c5d7c944.tar.gz PeerTube-16c016e8b1d5ca46343d3363f9a49e24c5d7c944.tar.zst PeerTube-16c016e8b1d5ca46343d3363f9a49e24c5d7c944.zip |
Stricter models typing
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r-- | server/models/video/video.ts | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index f8a099d9c..749ef7197 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -31,6 +31,7 @@ import { LiveManager } from '@server/lib/live-manager' | |||
31 | import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths' | 31 | import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths' |
32 | import { getServerActor } from '@server/models/application/application' | 32 | import { getServerActor } from '@server/models/application/application' |
33 | import { ModelCache } from '@server/models/model-cache' | 33 | import { ModelCache } from '@server/models/model-cache' |
34 | import { AttributesOnly } from '@shared/core-utils' | ||
34 | import { VideoFile } from '@shared/models/videos/video-file.model' | 35 | import { VideoFile } from '@shared/models/videos/video-file.model' |
35 | import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' | 36 | import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' |
36 | import { VideoObject } from '../../../shared/models/activitypub/objects' | 37 | import { VideoObject } from '../../../shared/models/activitypub/objects' |
@@ -489,7 +490,7 @@ export type AvailableForListIDsOptions = { | |||
489 | } | 490 | } |
490 | ] | 491 | ] |
491 | }) | 492 | }) |
492 | export class VideoModel extends Model { | 493 | export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { |
493 | 494 | ||
494 | @AllowNull(false) | 495 | @AllowNull(false) |
495 | @Default(DataType.UUIDV4) | 496 | @Default(DataType.UUIDV4) |
@@ -1617,7 +1618,7 @@ export class VideoModel extends Model { | |||
1617 | includeLocalVideos: true | 1618 | includeLocalVideos: true |
1618 | } | 1619 | } |
1619 | 1620 | ||
1620 | const { query, replacements } = buildListQuery(VideoModel, queryOptions) | 1621 | const { query, replacements } = buildListQuery(VideoModel.sequelize, queryOptions) |
1621 | 1622 | ||
1622 | return this.sequelize.query<any>(query, { replacements, type: QueryTypes.SELECT }) | 1623 | return this.sequelize.query<any>(query, { replacements, type: QueryTypes.SELECT }) |
1623 | .then(rows => rows.map(r => r[field])) | 1624 | .then(rows => rows.map(r => r[field])) |
@@ -1645,7 +1646,7 @@ export class VideoModel extends Model { | |||
1645 | if (countVideos !== true) return Promise.resolve(undefined) | 1646 | if (countVideos !== true) return Promise.resolve(undefined) |
1646 | 1647 | ||
1647 | const countOptions = Object.assign({}, options, { isCount: true }) | 1648 | const countOptions = Object.assign({}, options, { isCount: true }) |
1648 | const { query: queryCount, replacements: replacementsCount } = buildListQuery(VideoModel, countOptions) | 1649 | const { query: queryCount, replacements: replacementsCount } = buildListQuery(VideoModel.sequelize, countOptions) |
1649 | 1650 | ||
1650 | return VideoModel.sequelize.query<any>(queryCount, { replacements: replacementsCount, type: QueryTypes.SELECT }) | 1651 | return VideoModel.sequelize.query<any>(queryCount, { replacements: replacementsCount, type: QueryTypes.SELECT }) |
1651 | .then(rows => rows.length !== 0 ? rows[0].total : 0) | 1652 | .then(rows => rows.length !== 0 ? rows[0].total : 0) |
@@ -1654,7 +1655,7 @@ export class VideoModel extends Model { | |||
1654 | function getModels () { | 1655 | function getModels () { |
1655 | if (options.count === 0) return Promise.resolve([]) | 1656 | if (options.count === 0) return Promise.resolve([]) |
1656 | 1657 | ||
1657 | const { query, replacements, order } = buildListQuery(VideoModel, options) | 1658 | const { query, replacements, order } = buildListQuery(VideoModel.sequelize, options) |
1658 | const queryModels = wrapForAPIResults(query, replacements, options, order) | 1659 | const queryModels = wrapForAPIResults(query, replacements, options, order) |
1659 | 1660 | ||
1660 | return VideoModel.sequelize.query<any>(queryModels, { replacements, type: QueryTypes.SELECT, nest: true }) | 1661 | return VideoModel.sequelize.query<any>(queryModels, { replacements, type: QueryTypes.SELECT, nest: true }) |