aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/account.ts6
-rw-r--r--server/models/video/video-playlist.ts30
2 files changed, 31 insertions, 5 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index 3fb766c8a..7cc40f631 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -10,7 +10,8 @@ import {
10 ForeignKey, 10 ForeignKey,
11 HasMany, 11 HasMany,
12 Is, 12 Is,
13 Model, Scopes, 13 Model,
14 Scopes,
14 Table, 15 Table,
15 UpdatedAt 16 UpdatedAt
16} from 'sequelize-typescript' 17} from 'sequelize-typescript'
@@ -26,7 +27,6 @@ import { VideoCommentModel } from '../video/video-comment'
26import { UserModel } from './user' 27import { UserModel } from './user'
27import { CONFIG } from '../../initializers' 28import { CONFIG } from '../../initializers'
28import { AvatarModel } from '../avatar/avatar' 29import { AvatarModel } from '../avatar/avatar'
29import { WhereOptions } from 'sequelize'
30import { VideoPlaylistModel } from '../video/video-playlist' 30import { VideoPlaylistModel } from '../video/video-playlist'
31 31
32export enum ScopeNames { 32export enum ScopeNames {
@@ -42,7 +42,7 @@ export enum ScopeNames {
42 ] 42 ]
43}) 43})
44@Scopes({ 44@Scopes({
45 [ ScopeNames.SUMMARY ]: (whereActor?: WhereOptions<ActorModel>) => { 45 [ ScopeNames.SUMMARY ]: (whereActor?: Sequelize.WhereOptions<ActorModel>) => {
46 return { 46 return {
47 attributes: [ 'id', 'name' ], 47 attributes: [ 'id', 'name' ],
48 include: [ 48 include: [
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts
index ce49f77ec..4d2ea0a66 100644
--- a/server/models/video/video-playlist.ts
+++ b/server/models/video/video-playlist.ts
@@ -47,7 +47,8 @@ enum ScopeNames {
47 AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', 47 AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST',
48 WITH_VIDEOS_LENGTH = 'WITH_VIDEOS_LENGTH', 48 WITH_VIDEOS_LENGTH = 'WITH_VIDEOS_LENGTH',
49 WITH_ACCOUNT_AND_CHANNEL_SUMMARY = 'WITH_ACCOUNT_AND_CHANNEL_SUMMARY', 49 WITH_ACCOUNT_AND_CHANNEL_SUMMARY = 'WITH_ACCOUNT_AND_CHANNEL_SUMMARY',
50 WITH_ACCOUNT = 'WITH_ACCOUNT' 50 WITH_ACCOUNT = 'WITH_ACCOUNT',
51 WITH_ACCOUNT_AND_CHANNEL = 'WITH_ACCOUNT_AND_CHANNEL'
51} 52}
52 53
53type AvailableForListOptions = { 54type AvailableForListOptions = {
@@ -89,6 +90,18 @@ type AvailableForListOptions = {
89 } 90 }
90 ] 91 ]
91 }, 92 },
93 [ ScopeNames.WITH_ACCOUNT_AND_CHANNEL ]: {
94 include: [
95 {
96 model: () => AccountModel,
97 required: true
98 },
99 {
100 model: () => VideoChannelModel,
101 required: false
102 }
103 ]
104 },
92 [ ScopeNames.AVAILABLE_FOR_LIST ]: (options: AvailableForListOptions) => { 105 [ ScopeNames.AVAILABLE_FOR_LIST ]: (options: AvailableForListOptions) => {
93 // Only list local playlists OR playlists that are on an instance followed by actorId 106 // Only list local playlists OR playlists that are on an instance followed by actorId
94 const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId) 107 const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId)
@@ -317,7 +330,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
317 .then(e => !!e) 330 .then(e => !!e)
318 } 331 }
319 332
320 static loadWithAccountAndChannel (id: number | string, transaction: Sequelize.Transaction) { 333 static loadWithAccountAndChannelSummary (id: number | string, transaction: Sequelize.Transaction) {
321 const where = buildWhereIdOrUUID(id) 334 const where = buildWhereIdOrUUID(id)
322 335
323 const query = { 336 const query = {
@@ -330,6 +343,19 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
330 .findOne(query) 343 .findOne(query)
331 } 344 }
332 345
346 static loadWithAccountAndChannel (id: number | string, transaction: Sequelize.Transaction) {
347 const where = buildWhereIdOrUUID(id)
348
349 const query = {
350 where,
351 transaction
352 }
353
354 return VideoPlaylistModel
355 .scope([ ScopeNames.WITH_ACCOUNT_AND_CHANNEL, ScopeNames.WITH_VIDEOS_LENGTH ])
356 .findOne(query)
357 }
358
333 static loadByUrlAndPopulateAccount (url: string) { 359 static loadByUrlAndPopulateAccount (url: string) {
334 const query = { 360 const query = {
335 where: { 361 where: {