diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-18 11:28:17 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-24 16:26:20 +0200 |
commit | 1735c825726edaa0af5035cb6cbb0cc0db502c6d (patch) | |
tree | 7bbb442f2cb4d7be58a4e08d87f5974403a3047c /server/models/video/video-playlist.ts | |
parent | e8bafea35bc930cb8ac5b2d521a188642a1adffe (diff) | |
download | PeerTube-1735c825726edaa0af5035cb6cbb0cc0db502c6d.tar.gz PeerTube-1735c825726edaa0af5035cb6cbb0cc0db502c6d.tar.zst PeerTube-1735c825726edaa0af5035cb6cbb0cc0db502c6d.zip |
Update sequelize
Diffstat (limited to 'server/models/video/video-playlist.ts')
-rw-r--r-- | server/models/video/video-playlist.ts | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 073609c24..3e436acfc 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts | |||
@@ -15,7 +15,6 @@ import { | |||
15 | Table, | 15 | Table, |
16 | UpdatedAt | 16 | UpdatedAt |
17 | } from 'sequelize-typescript' | 17 | } from 'sequelize-typescript' |
18 | import * as Sequelize from 'sequelize' | ||
19 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' | 18 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' |
20 | import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid } from '../utils' | 19 | import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid } from '../utils' |
21 | import { | 20 | import { |
@@ -43,6 +42,7 @@ import { activityPubCollectionPagination } from '../../helpers/activitypub' | |||
43 | import { VideoPlaylistType } from '../../../shared/models/videos/playlist/video-playlist-type.model' | 42 | import { VideoPlaylistType } from '../../../shared/models/videos/playlist/video-playlist-type.model' |
44 | import { ThumbnailModel } from './thumbnail' | 43 | import { ThumbnailModel } from './thumbnail' |
45 | import { ActivityIconObject } from '../../../shared/models/activitypub/objects' | 44 | import { ActivityIconObject } from '../../../shared/models/activitypub/objects' |
45 | import { fn, literal, Op, Transaction } from 'sequelize' | ||
46 | 46 | ||
47 | enum ScopeNames { | 47 | enum ScopeNames { |
48 | AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', | 48 | AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', |
@@ -74,7 +74,11 @@ type AvailableForListOptions = { | |||
74 | attributes: { | 74 | attributes: { |
75 | include: [ | 75 | include: [ |
76 | [ | 76 | [ |
77 | Sequelize.literal('(SELECT COUNT("id") FROM "videoPlaylistElement" WHERE "videoPlaylistId" = "VideoPlaylistModel"."id")'), | 77 | fn('COUNT', 'toto'), |
78 | 'coucou' | ||
79 | ], | ||
80 | [ | ||
81 | literal('(SELECT COUNT("id") FROM "videoPlaylistElement" WHERE "videoPlaylistId" = "VideoPlaylistModel"."id")'), | ||
78 | 'videosLength' | 82 | 'videosLength' |
79 | ] | 83 | ] |
80 | ] | 84 | ] |
@@ -116,13 +120,13 @@ type AvailableForListOptions = { | |||
116 | // Only list local playlists OR playlists that are on an instance followed by actorId | 120 | // Only list local playlists OR playlists that are on an instance followed by actorId |
117 | const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId) | 121 | const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId) |
118 | const actorWhere = { | 122 | const actorWhere = { |
119 | [ Sequelize.Op.or ]: [ | 123 | [ Op.or ]: [ |
120 | { | 124 | { |
121 | serverId: null | 125 | serverId: null |
122 | }, | 126 | }, |
123 | { | 127 | { |
124 | serverId: { | 128 | serverId: { |
125 | [ Sequelize.Op.in ]: Sequelize.literal(inQueryInstanceFollow) | 129 | [ Op.in ]: literal(inQueryInstanceFollow) |
126 | } | 130 | } |
127 | } | 131 | } |
128 | ] | 132 | ] |
@@ -155,7 +159,7 @@ type AvailableForListOptions = { | |||
155 | } | 159 | } |
156 | 160 | ||
157 | const where = { | 161 | const where = { |
158 | [Sequelize.Op.and]: whereAnd | 162 | [Op.and]: whereAnd |
159 | } | 163 | } |
160 | 164 | ||
161 | const accountScope = { | 165 | const accountScope = { |
@@ -206,7 +210,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
206 | name: string | 210 | name: string |
207 | 211 | ||
208 | @AllowNull(true) | 212 | @AllowNull(true) |
209 | @Is('VideoPlaylistDescription', value => throwIfNotValid(value, isVideoPlaylistDescriptionValid, 'description')) | 213 | @Is('VideoPlaylistDescription', value => throwIfNotValid(value, isVideoPlaylistDescriptionValid, 'description', true)) |
210 | @Column | 214 | @Column |
211 | description: string | 215 | description: string |
212 | 216 | ||
@@ -344,7 +348,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
344 | model: VideoPlaylistElementModel.unscoped(), | 348 | model: VideoPlaylistElementModel.unscoped(), |
345 | where: { | 349 | where: { |
346 | videoId: { | 350 | videoId: { |
347 | [Sequelize.Op.any]: videoIds | 351 | [Op.any]: videoIds |
348 | } | 352 | } |
349 | }, | 353 | }, |
350 | required: true | 354 | required: true |
@@ -368,7 +372,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
368 | .then(e => !!e) | 372 | .then(e => !!e) |
369 | } | 373 | } |
370 | 374 | ||
371 | static loadWithAccountAndChannelSummary (id: number | string, transaction: Sequelize.Transaction) { | 375 | static loadWithAccountAndChannelSummary (id: number | string, transaction: Transaction) { |
372 | const where = buildWhereIdOrUUID(id) | 376 | const where = buildWhereIdOrUUID(id) |
373 | 377 | ||
374 | const query = { | 378 | const query = { |
@@ -381,7 +385,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
381 | .findOne(query) | 385 | .findOne(query) |
382 | } | 386 | } |
383 | 387 | ||
384 | static loadWithAccountAndChannel (id: number | string, transaction: Sequelize.Transaction) { | 388 | static loadWithAccountAndChannel (id: number | string, transaction: Transaction) { |
385 | const where = buildWhereIdOrUUID(id) | 389 | const where = buildWhereIdOrUUID(id) |
386 | 390 | ||
387 | const query = { | 391 | const query = { |
@@ -412,7 +416,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
412 | return VIDEO_PLAYLIST_TYPES[type] || 'Unknown' | 416 | return VIDEO_PLAYLIST_TYPES[type] || 'Unknown' |
413 | } | 417 | } |
414 | 418 | ||
415 | static resetPlaylistsOfChannel (videoChannelId: number, transaction: Sequelize.Transaction) { | 419 | static resetPlaylistsOfChannel (videoChannelId: number, transaction: Transaction) { |
416 | const query = { | 420 | const query = { |
417 | where: { | 421 | where: { |
418 | videoChannelId | 422 | videoChannelId |
@@ -489,7 +493,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
489 | label: VideoPlaylistModel.getTypeLabel(this.type) | 493 | label: VideoPlaylistModel.getTypeLabel(this.type) |
490 | }, | 494 | }, |
491 | 495 | ||
492 | videosLength: this.get('videosLength'), | 496 | videosLength: this.get('videosLength') as number, |
493 | 497 | ||
494 | createdAt: this.createdAt, | 498 | createdAt: this.createdAt, |
495 | updatedAt: this.updatedAt, | 499 | updatedAt: this.updatedAt, |
@@ -499,7 +503,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
499 | } | 503 | } |
500 | } | 504 | } |
501 | 505 | ||
502 | toActivityPubObject (page: number, t: Sequelize.Transaction): Promise<PlaylistObject> { | 506 | toActivityPubObject (page: number, t: Transaction): Promise<PlaylistObject> { |
503 | const handler = (start: number, count: number) => { | 507 | const handler = (start: number, count: number) => { |
504 | return VideoPlaylistElementModel.listUrlsOfForAP(this.id, start, count, t) | 508 | return VideoPlaylistElementModel.listUrlsOfForAP(this.id, start, count, t) |
505 | } | 509 | } |