import { FindOptions, ModelIndexesOptions, Op } from 'sequelize'
import { AvatarModel } from '../avatar/avatar'
import { VideoPlaylistModel } from './video-playlist'
+import * as Bluebird from 'bluebird'
+import {
+ MChannelAccountDefault,
+ MChannelActor,
+ MChannelActorAccountDefault,
+ MChannelActorAccountDefaultVideos
+} from '../../typings/models/video'
// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
const indexes: ModelIndexesOptions[] = [
]
export enum ScopeNames {
- AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST',
+ FOR_API = 'FOR_API',
WITH_ACCOUNT = 'WITH_ACCOUNT',
WITH_ACTOR = 'WITH_ACTOR',
WITH_VIDEOS = 'WITH_VIDEOS',
@Scopes(() => ({
[ScopeNames.SUMMARY]: (options: SummaryOptions = {}) => {
const base: FindOptions = {
- attributes: [ 'name', 'description', 'id', 'actorId' ],
+ attributes: [ 'id', 'name', 'description', 'actorId' ],
include: [
{
- attributes: [ 'preferredUsername', 'url', 'serverId', 'avatarId' ],
+ attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ],
model: ActorModel.unscoped(),
required: true,
include: [
return base
},
- [ScopeNames.AVAILABLE_FOR_LIST]: (options: AvailableForListOptions) => {
+ [ScopeNames.FOR_API]: (options: AvailableForListOptions) => {
// Only list local channels OR channels that are on an instance followed by actorId
const inQueryInstanceFollow = buildServerIdsFollowedBy(options.actorId)
}
const scopes = {
- method: [ ScopeNames.AVAILABLE_FOR_LIST, { actorId } as AvailableForListOptions ]
+ method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ]
}
return VideoChannelModel
.scope(scopes)
})
}
- static listLocalsForSitemap (sort: string) {
+ static listLocalsForSitemap (sort: string): Bluebird<MChannelActor[]> {
const query = {
attributes: [ ],
offset: 0,
}
const scopes = {
- method: [ ScopeNames.AVAILABLE_FOR_LIST, { actorId: options.actorId } as AvailableForListOptions ]
+ method: [ ScopeNames.FOR_API, { actorId: options.actorId } as AvailableForListOptions ]
}
return VideoChannelModel
.scope(scopes)
})
}
- static loadByIdAndPopulateAccount (id: number) {
+ static loadByIdAndPopulateAccount (id: number): Bluebird<MChannelActorAccountDefault> {
return VideoChannelModel.unscoped()
.scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
.findByPk(id)
}
- static loadByIdAndAccount (id: number, accountId: number) {
+ static loadByIdAndAccount (id: number, accountId: number): Bluebird<MChannelActorAccountDefault> {
const query = {
where: {
id,
.findOne(query)
}
- static loadAndPopulateAccount (id: number) {
+ static loadAndPopulateAccount (id: number): Bluebird<MChannelActorAccountDefault> {
return VideoChannelModel.unscoped()
.scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
.findByPk(id)
}
- static loadByUrlAndPopulateAccount (url: string) {
+ static loadByUrlAndPopulateAccount (url: string): Bluebird<MChannelAccountDefault> {
const query = {
include: [
{
return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host)
}
- static loadLocalByNameAndPopulateAccount (name: string) {
+ static loadLocalByNameAndPopulateAccount (name: string): Bluebird<MChannelActorAccountDefault> {
const query = {
include: [
{
.findOne(query)
}
- static loadByNameAndHostAndPopulateAccount (name: string, host: string) {
+ static loadByNameAndHostAndPopulateAccount (name: string, host: string): Bluebird<MChannelActorAccountDefault> {
const query = {
include: [
{
.findOne(query)
}
- static loadAndPopulateAccountAndVideos (id: number) {
+ static loadAndPopulateAccountAndVideos (id: number): Bluebird<MChannelActorAccountDefaultVideos> {
const options = {
include: [
VideoModel