From 09979f8959425390b879bce22101a9bc061ae9a0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 5 Mar 2019 11:30:43 +0100 Subject: Refactor video playlist middlewares --- server/models/video/video-playlist.ts | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'server/models/video/video-playlist.ts') 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 { AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', WITH_VIDEOS_LENGTH = 'WITH_VIDEOS_LENGTH', WITH_ACCOUNT_AND_CHANNEL_SUMMARY = 'WITH_ACCOUNT_AND_CHANNEL_SUMMARY', - WITH_ACCOUNT = 'WITH_ACCOUNT' + WITH_ACCOUNT = 'WITH_ACCOUNT', + WITH_ACCOUNT_AND_CHANNEL = 'WITH_ACCOUNT_AND_CHANNEL' } type AvailableForListOptions = { @@ -89,6 +90,18 @@ type AvailableForListOptions = { } ] }, + [ ScopeNames.WITH_ACCOUNT_AND_CHANNEL ]: { + include: [ + { + model: () => AccountModel, + required: true + }, + { + model: () => VideoChannelModel, + required: false + } + ] + }, [ ScopeNames.AVAILABLE_FOR_LIST ]: (options: AvailableForListOptions) => { // Only list local playlists OR playlists that are on an instance followed by actorId const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId) @@ -317,7 +330,7 @@ export class VideoPlaylistModel extends Model { .then(e => !!e) } - static loadWithAccountAndChannel (id: number | string, transaction: Sequelize.Transaction) { + static loadWithAccountAndChannelSummary (id: number | string, transaction: Sequelize.Transaction) { const where = buildWhereIdOrUUID(id) const query = { @@ -330,6 +343,19 @@ export class VideoPlaylistModel extends Model { .findOne(query) } + static loadWithAccountAndChannel (id: number | string, transaction: Sequelize.Transaction) { + const where = buildWhereIdOrUUID(id) + + const query = { + where, + transaction + } + + return VideoPlaylistModel + .scope([ ScopeNames.WITH_ACCOUNT_AND_CHANNEL, ScopeNames.WITH_VIDEOS_LENGTH ]) + .findOne(query) + } + static loadByUrlAndPopulateAccount (url: string) { const query = { where: { -- cgit v1.2.3