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.ts21
1 files changed, 14 insertions, 7 deletions
diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts
index 4bd8114cf..8b62dd05f 100644
--- a/server/models/account/account-video-rate.ts
+++ b/server/models/account/account-video-rate.ts
@@ -10,6 +10,8 @@ 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 { MAccountVideoRate, MAccountVideoRateAccountUrl, MAccountVideoRateAccountVideo } from '@server/typings/models/video/video-rate'
13 15
14/* 16/*
15 Account rates per video. 17 Account rates per video.
@@ -77,7 +79,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
77 }) 79 })
78 Account: AccountModel 80 Account: AccountModel
79 81
80 static load (accountId: number, videoId: number, transaction?: Transaction) { 82 static load (accountId: number, videoId: number, transaction?: Transaction): Bluebird<MAccountVideoRate> {
81 const options: FindOptions = { 83 const options: FindOptions = {
82 where: { 84 where: {
83 accountId, 85 accountId,
@@ -89,7 +91,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
89 return AccountVideoRateModel.findOne(options) 91 return AccountVideoRateModel.findOne(options)
90 } 92 }
91 93
92 static loadByAccountAndVideoOrUrl (accountId: number, videoId: number, url: string, transaction?: Transaction) { 94 static loadByAccountAndVideoOrUrl (accountId: number, videoId: number, url: string, t?: Transaction): Bluebird<MAccountVideoRate> {
93 const options: FindOptions = { 95 const options: FindOptions = {
94 where: { 96 where: {
95 [ Op.or]: [ 97 [ Op.or]: [
@@ -103,7 +105,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
103 ] 105 ]
104 } 106 }
105 } 107 }
106 if (transaction) options.transaction = transaction 108 if (t) options.transaction = t
107 109
108 return AccountVideoRateModel.findOne(options) 110 return AccountVideoRateModel.findOne(options)
109 } 111 }
@@ -140,7 +142,12 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
140 return AccountVideoRateModel.findAndCountAll(query) 142 return AccountVideoRateModel.findAndCountAll(query)
141 } 143 }
142 144
143 static loadLocalAndPopulateVideo (rateType: VideoRateType, accountName: string, videoId: number, transaction?: Transaction) { 145 static loadLocalAndPopulateVideo (
146 rateType: VideoRateType,
147 accountName: string,
148 videoId: number,
149 t?: Transaction
150 ): Bluebird<MAccountVideoRateAccountVideo> {
144 const options: FindOptions = { 151 const options: FindOptions = {
145 where: { 152 where: {
146 videoId, 153 videoId,
@@ -152,7 +159,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
152 required: true, 159 required: true,
153 include: [ 160 include: [
154 { 161 {
155 attributes: [ 'id', 'url', 'preferredUsername' ], 162 attributes: [ 'id', 'url', 'followersUrl', 'preferredUsername' ],
156 model: ActorModel.unscoped(), 163 model: ActorModel.unscoped(),
157 required: true, 164 required: true,
158 where: { 165 where: {
@@ -167,7 +174,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
167 } 174 }
168 ] 175 ]
169 } 176 }
170 if (transaction) options.transaction = transaction 177 if (t) options.transaction = t
171 178
172 return AccountVideoRateModel.findOne(options) 179 return AccountVideoRateModel.findOne(options)
173 } 180 }
@@ -208,7 +215,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
208 ] 215 ]
209 } 216 }
210 217
211 return AccountVideoRateModel.findAndCountAll(query) 218 return AccountVideoRateModel.findAndCountAll<MAccountVideoRateAccountUrl>(query)
212 } 219 }
213 220
214 static cleanOldRatesOf (videoId: number, type: VideoRateType, beforeUpdatedAt: Date) { 221 static cleanOldRatesOf (videoId: number, type: VideoRateType, beforeUpdatedAt: Date) {