aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/account-video-rate.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/account/account-video-rate.ts')
-rw-r--r--server/models/account/account-video-rate.ts28
1 files changed, 20 insertions, 8 deletions
diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts
index 4bd8114cf..a6edbeee8 100644
--- a/server/models/account/account-video-rate.ts
+++ b/server/models/account/account-video-rate.ts
@@ -10,6 +10,13 @@ import { buildLocalAccountIdsIn, getSort, throwIfNotValid } from '../utils'
10import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 10import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
11import { AccountVideoRate } from '../../../shared' 11import { AccountVideoRate } from '../../../shared'
12import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from '../video/video-channel' 12import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from '../video/video-channel'
13import * as Bluebird from 'bluebird'
14import {
15 MAccountVideoRate,
16 MAccountVideoRateAccountUrl,
17 MAccountVideoRateAccountVideo,
18 MAccountVideoRateFormattable
19} from '@server/typings/models/video/video-rate'
13 20
14/* 21/*
15 Account rates per video. 22 Account rates per video.
@@ -77,7 +84,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
77 }) 84 })
78 Account: AccountModel 85 Account: AccountModel
79 86
80 static load (accountId: number, videoId: number, transaction?: Transaction) { 87 static load (accountId: number, videoId: number, transaction?: Transaction): Bluebird<MAccountVideoRate> {
81 const options: FindOptions = { 88 const options: FindOptions = {
82 where: { 89 where: {
83 accountId, 90 accountId,
@@ -89,7 +96,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
89 return AccountVideoRateModel.findOne(options) 96 return AccountVideoRateModel.findOne(options)
90 } 97 }
91 98
92 static loadByAccountAndVideoOrUrl (accountId: number, videoId: number, url: string, transaction?: Transaction) { 99 static loadByAccountAndVideoOrUrl (accountId: number, videoId: number, url: string, t?: Transaction): Bluebird<MAccountVideoRate> {
93 const options: FindOptions = { 100 const options: FindOptions = {
94 where: { 101 where: {
95 [ Op.or]: [ 102 [ Op.or]: [
@@ -103,7 +110,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
103 ] 110 ]
104 } 111 }
105 } 112 }
106 if (transaction) options.transaction = transaction 113 if (t) options.transaction = t
107 114
108 return AccountVideoRateModel.findOne(options) 115 return AccountVideoRateModel.findOne(options)
109 } 116 }
@@ -140,7 +147,12 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
140 return AccountVideoRateModel.findAndCountAll(query) 147 return AccountVideoRateModel.findAndCountAll(query)
141 } 148 }
142 149
143 static loadLocalAndPopulateVideo (rateType: VideoRateType, accountName: string, videoId: number, transaction?: Transaction) { 150 static loadLocalAndPopulateVideo (
151 rateType: VideoRateType,
152 accountName: string,
153 videoId: number,
154 t?: Transaction
155 ): Bluebird<MAccountVideoRateAccountVideo> {
144 const options: FindOptions = { 156 const options: FindOptions = {
145 where: { 157 where: {
146 videoId, 158 videoId,
@@ -152,7 +164,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
152 required: true, 164 required: true,
153 include: [ 165 include: [
154 { 166 {
155 attributes: [ 'id', 'url', 'preferredUsername' ], 167 attributes: [ 'id', 'url', 'followersUrl', 'preferredUsername' ],
156 model: ActorModel.unscoped(), 168 model: ActorModel.unscoped(),
157 required: true, 169 required: true,
158 where: { 170 where: {
@@ -167,7 +179,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
167 } 179 }
168 ] 180 ]
169 } 181 }
170 if (transaction) options.transaction = transaction 182 if (t) options.transaction = t
171 183
172 return AccountVideoRateModel.findOne(options) 184 return AccountVideoRateModel.findOne(options)
173 } 185 }
@@ -208,7 +220,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
208 ] 220 ]
209 } 221 }
210 222
211 return AccountVideoRateModel.findAndCountAll(query) 223 return AccountVideoRateModel.findAndCountAll<MAccountVideoRateAccountUrl>(query)
212 } 224 }
213 225
214 static cleanOldRatesOf (videoId: number, type: VideoRateType, beforeUpdatedAt: Date) { 226 static cleanOldRatesOf (videoId: number, type: VideoRateType, beforeUpdatedAt: Date) {
@@ -241,7 +253,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
241 }) 253 })
242 } 254 }
243 255
244 toFormattedJSON (): AccountVideoRate { 256 toFormattedJSON (this: MAccountVideoRateFormattable): AccountVideoRate {
245 return { 257 return {
246 video: this.Video.toFormattedJSON(), 258 video: this.Video.toFormattedJSON(),
247 rating: this.type 259 rating: this.type