aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/account')
-rw-r--r--server/models/account/account-video-rate.ts43
1 files changed, 42 insertions, 1 deletions
diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts
index e5d39582b..f462df4b3 100644
--- a/server/models/account/account-video-rate.ts
+++ b/server/models/account/account-video-rate.ts
@@ -7,8 +7,10 @@ import { CONSTRAINTS_FIELDS, VIDEO_RATE_TYPES } from '../../initializers'
7import { VideoModel } from '../video/video' 7import { VideoModel } from '../video/video'
8import { AccountModel } from './account' 8import { AccountModel } from './account'
9import { ActorModel } from '../activitypub/actor' 9import { ActorModel } from '../activitypub/actor'
10import { throwIfNotValid } from '../utils' 10import { throwIfNotValid, getSort } from '../utils'
11import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 11import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
12import { AccountVideoRate } from '../../../shared'
13import { VideoChannelModel, ScopeNames as VideoChannelScopeNames } from '../video/video-channel'
12 14
13/* 15/*
14 Account rates per video. 16 Account rates per video.
@@ -88,6 +90,38 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
88 return AccountVideoRateModel.findOne(options) 90 return AccountVideoRateModel.findOne(options)
89 } 91 }
90 92
93 static listByAccountForApi (options: {
94 start: number,
95 count: number,
96 sort: string,
97 type?: string,
98 accountId: number
99 }) {
100 const query: IFindOptions<AccountVideoRateModel> = {
101 offset: options.start,
102 limit: options.count,
103 order: getSort(options.sort),
104 where: {
105 accountId: options.accountId
106 },
107 include: [
108 {
109 model: VideoModel,
110 required: true,
111 include: [
112 {
113 model: VideoChannelModel.scope({ method: [VideoChannelScopeNames.SUMMARY, true] }),
114 required: true
115 }
116 ]
117 }
118 ]
119 }
120 if (options.type) query.where['type'] = options.type
121
122 return AccountVideoRateModel.findAndCountAll(query)
123 }
124
91 static loadLocalAndPopulateVideo (rateType: VideoRateType, accountName: string, videoId: number, transaction?: Transaction) { 125 static loadLocalAndPopulateVideo (rateType: VideoRateType, accountName: string, videoId: number, transaction?: Transaction) {
92 const options: IFindOptions<AccountVideoRateModel> = { 126 const options: IFindOptions<AccountVideoRateModel> = {
93 where: { 127 where: {
@@ -185,4 +219,11 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
185 else if (type === 'dislike') await VideoModel.increment({ dislikes: -deleted }, options) 219 else if (type === 'dislike') await VideoModel.increment({ dislikes: -deleted }, options)
186 }) 220 })
187 } 221 }
222
223 toFormattedJSON (): AccountVideoRate {
224 return {
225 video: this.Video.toFormattedJSON(),
226 rating: this.type
227 }
228 }
188} 229}