diff options
Diffstat (limited to 'server/models/account/account-video-rate.ts')
-rw-r--r-- | server/models/account/account-video-rate.ts | 43 |
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' | |||
7 | import { VideoModel } from '../video/video' | 7 | import { VideoModel } from '../video/video' |
8 | import { AccountModel } from './account' | 8 | import { AccountModel } from './account' |
9 | import { ActorModel } from '../activitypub/actor' | 9 | import { ActorModel } from '../activitypub/actor' |
10 | import { throwIfNotValid } from '../utils' | 10 | import { throwIfNotValid, getSort } from '../utils' |
11 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 11 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
12 | import { AccountVideoRate } from '../../../shared' | ||
13 | import { 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 | } |