From b49f22d8f9a52ab75fd38db2d377249eb58fa678 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 8 Dec 2020 14:30:29 +0100 Subject: Upgrade sequelize to v6 --- server/models/video/video-channel.ts | 78 ++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'server/models/video/video-channel.ts') diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 0c8aef18f..178878c55 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -1,5 +1,4 @@ -import * as Bluebird from 'bluebird' -import { FindOptions, literal, Op, ScopeOptions } from 'sequelize' +import { FindOptions, Includeable, literal, Op, ScopeOptions } from 'sequelize' import { AllowNull, BeforeDestroy, @@ -119,30 +118,31 @@ export type SummaryOptions = { } }, [ScopeNames.SUMMARY]: (options: SummaryOptions = {}) => { + const include: Includeable[] = [ + { + attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ], + model: ActorModel.unscoped(), + required: options.actorRequired ?? true, + include: [ + { + attributes: [ 'host' ], + model: ServerModel.unscoped(), + required: false + }, + { + model: AvatarModel.unscoped(), + required: false + } + ] + } + ] + const base: FindOptions = { - attributes: [ 'id', 'name', 'description', 'actorId' ], - include: [ - { - attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ], - model: ActorModel.unscoped(), - required: options.actorRequired ?? true, - include: [ - { - attributes: [ 'host' ], - model: ServerModel.unscoped(), - required: false - }, - { - model: AvatarModel.unscoped(), - required: false - } - ] - } - ] + attributes: [ 'id', 'name', 'description', 'actorId' ] } if (options.withAccount === true) { - base.include.push({ + include.push({ model: AccountModel.scope({ method: [ AccountModelScopeNames.SUMMARY, { withAccountBlockerIds: options.withAccountBlockerIds } as AccountSummaryOptions ] }), @@ -150,6 +150,8 @@ export type SummaryOptions = { }) } + base.include = include + return base }, [ScopeNames.WITH_ACCOUNT]: { @@ -221,7 +223,7 @@ export type SummaryOptions = { } ] }) -export class VideoChannelModel extends Model { +export class VideoChannelModel extends Model { @AllowNull(false) @Is('VideoChannelName', value => throwIfNotValid(value, isVideoChannelNameValid, 'name')) @@ -328,18 +330,17 @@ export class VideoChannelModel extends Model { order: getSort(parameters.sort) } - const scopes = { - method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ] - } return VideoChannelModel - .scope(scopes) + .scope({ + method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ] + }) .findAndCountAll(query) .then(({ rows, count }) => { return { total: count, data: rows } }) } - static listLocalsForSitemap (sort: string): Bluebird { + static listLocalsForSitemap (sort: string): Promise { const query = { attributes: [ ], offset: 0, @@ -391,11 +392,10 @@ export class VideoChannelModel extends Model { } } - const scopes = { - method: [ ScopeNames.FOR_API, { actorId: options.actorId } as AvailableForListOptions ] - } return VideoChannelModel - .scope(scopes) + .scope({ + method: [ ScopeNames.FOR_API, { actorId: options.actorId } as AvailableForListOptions ] + }) .findAndCountAll(query) .then(({ rows, count }) => { return { total: count, data: rows } @@ -457,13 +457,13 @@ export class VideoChannelModel extends Model { }) } - static loadByIdAndPopulateAccount (id: number): Bluebird { + static loadByIdAndPopulateAccount (id: number): Promise { return VideoChannelModel.unscoped() .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) .findByPk(id) } - static loadByIdAndAccount (id: number, accountId: number): Bluebird { + static loadByIdAndAccount (id: number, accountId: number): Promise { const query = { where: { id, @@ -476,13 +476,13 @@ export class VideoChannelModel extends Model { .findOne(query) } - static loadAndPopulateAccount (id: number): Bluebird { + static loadAndPopulateAccount (id: number): Promise { return VideoChannelModel.unscoped() .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) .findByPk(id) } - static loadByUrlAndPopulateAccount (url: string): Bluebird { + static loadByUrlAndPopulateAccount (url: string): Promise { const query = { include: [ { @@ -508,7 +508,7 @@ export class VideoChannelModel extends Model { return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host) } - static loadLocalByNameAndPopulateAccount (name: string): Bluebird { + static loadLocalByNameAndPopulateAccount (name: string): Promise { const query = { include: [ { @@ -527,7 +527,7 @@ export class VideoChannelModel extends Model { .findOne(query) } - static loadByNameAndHostAndPopulateAccount (name: string, host: string): Bluebird { + static loadByNameAndHostAndPopulateAccount (name: string, host: string): Promise { const query = { include: [ { @@ -552,7 +552,7 @@ export class VideoChannelModel extends Model { .findOne(query) } - static loadAndPopulateAccountAndVideos (id: number): Bluebird { + static loadAndPopulateAccountAndVideos (id: number): Promise { const options = { include: [ VideoModel -- cgit v1.2.3