})
}
- const channelInclude: Includeable[] = []
- const accountInclude: Includeable[] = []
+ const channelActorInclude: Includeable[] = []
+ const accountActorInclude: Includeable[] = []
if (options.forCount !== true) {
- accountInclude.push({
+ accountActorInclude.push({
model: ServerModel,
required: false
})
- accountInclude.push({
+ accountActorInclude.push({
model: ActorImageModel,
as: 'Avatars',
required: false
})
- channelInclude.push({
+ channelActorInclude.push({
model: ActorImageModel,
as: 'Avatars',
required: false
})
- channelInclude.push({
+ channelActorInclude.push({
model: ActorImageModel,
as: 'Banners',
required: false
}
if (options.forCount !== true || serverRequired) {
- channelInclude.push({
+ channelActorInclude.push({
model: ServerModel,
duplicating: false,
required: serverRequired,
where: {
[Op.and]: whereActorAnd
},
- include: channelInclude
+ include: channelActorInclude
},
{
model: AccountModel.unscoped(),
},
model: ActorModel.unscoped(),
required: true,
- include: accountInclude
+ include: accountActorInclude
}
]
}
')'
),
'viewsPerDay'
+ ],
+ [
+ literal(
+ '(' +
+ 'SELECT COALESCE(SUM("video".views), 0) AS totalViews ' +
+ 'FROM "video" ' +
+ 'WHERE "video"."channelId" = "VideoChannelModel"."id"' +
+ ')'
+ ),
+ 'totalViews'
]
]
}
}
}
- return VideoChannelModel.count(query)
+ return VideoChannelModel.unscoped().count(query)
}
static async getStats () {
}
}
- const scopes: string | ScopeOptions | (string | ScopeOptions)[] = [ ScopeNames.WITH_ACTOR_BANNER ]
+ const findScopes: string | ScopeOptions | (string | ScopeOptions)[] = [ ScopeNames.WITH_ACTOR_BANNER ]
if (options.withStats === true) {
- scopes.push({
+ findScopes.push({
method: [ ScopeNames.WITH_STATS, { daysPrior: 30 } as AvailableWithStatsOptions ]
})
}
return Promise.all([
- VideoChannelModel.scope(scopes).count(getQuery(true)),
- VideoChannelModel.scope(scopes).findAll(getQuery(false))
+ VideoChannelModel.unscoped().count(getQuery(true)),
+ VideoChannelModel.scope(findScopes).findAll(getQuery(false))
]).then(([ total, data ]) => ({ total, data }))
}
})
}
+ const totalViews = this.get('totalViews') as number
+
const actor = this.Actor.toFormattedJSON()
const videoChannel = {
id: this.id,
videosCount,
viewsPerDay,
+ totalViews,
avatars: actor.avatars,