+ static loadByAccountAndVideoOrUrl (accountId: number, videoId: number, url: string, t?: Transaction): Promise<MAccountVideoRate> {
+ const options: FindOptions = {
+ where: {
+ [Op.or]: [
+ {
+ accountId,
+ videoId
+ },
+ {
+ url
+ }
+ ]
+ }
+ }
+ if (t) options.transaction = t
+
+ return AccountVideoRateModel.findOne(options)
+ }
+
+ static listByAccountForApi (options: {
+ start: number
+ count: number
+ sort: string
+ type?: string
+ accountId: number
+ }) {
+ const query: FindOptions = {
+ offset: options.start,
+ limit: options.count,
+ order: getSort(options.sort),
+ where: {
+ accountId: options.accountId
+ },
+ include: [
+ {
+ model: VideoModel,
+ required: true,
+ include: [
+ {
+ model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, { withAccount: true } as SummaryOptions ] }),
+ required: true
+ }
+ ]
+ }
+ ]
+ }
+ if (options.type) query.where['type'] = options.type
+
+ return AccountVideoRateModel.findAndCountAll(query)
+ }
+
+ static listRemoteRateUrlsOfLocalVideos () {
+ const query = `SELECT "accountVideoRate".url FROM "accountVideoRate" ` +
+ `INNER JOIN account ON account.id = "accountVideoRate"."accountId" ` +
+ `INNER JOIN actor ON actor.id = account."actorId" AND actor."serverId" IS NOT NULL ` +
+ `INNER JOIN video ON video.id = "accountVideoRate"."videoId" AND video.remote IS FALSE`
+
+ return AccountVideoRateModel.sequelize.query<{ url: string }>(query, {
+ type: QueryTypes.SELECT,
+ raw: true
+ }).then(rows => rows.map(r => r.url))
+ }
+
+ static loadLocalAndPopulateVideo (
+ rateType: VideoRateType,
+ accountName: string,
+ videoId: number,
+ t?: Transaction
+ ): Promise<MAccountVideoRateAccountVideo> {
+ const options: FindOptions = {