diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/account/account-video-rate.ts | 36 | ||||
-rw-r--r-- | server/models/video/video-comment.ts | 19 | ||||
-rw-r--r-- | server/models/video/video-share.ts | 29 |
3 files changed, 74 insertions, 10 deletions
diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts index 85af9e378..d5c214ecb 100644 --- a/server/models/account/account-video-rate.ts +++ b/server/models/account/account-video-rate.ts | |||
@@ -89,6 +89,25 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> { | |||
89 | return AccountVideoRateModel.findOne(options) | 89 | return AccountVideoRateModel.findOne(options) |
90 | } | 90 | } |
91 | 91 | ||
92 | static loadByAccountAndVideoOrUrl (accountId: number, videoId: number, url: string, transaction?: Transaction) { | ||
93 | const options: FindOptions = { | ||
94 | where: { | ||
95 | [ Op.or]: [ | ||
96 | { | ||
97 | accountId, | ||
98 | videoId | ||
99 | }, | ||
100 | { | ||
101 | url | ||
102 | } | ||
103 | ] | ||
104 | } | ||
105 | } | ||
106 | if (transaction) options.transaction = transaction | ||
107 | |||
108 | return AccountVideoRateModel.findOne(options) | ||
109 | } | ||
110 | |||
92 | static listByAccountForApi (options: { | 111 | static listByAccountForApi (options: { |
93 | start: number, | 112 | start: number, |
94 | count: number, | 113 | count: number, |
@@ -202,6 +221,23 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> { | |||
202 | videoId, | 221 | videoId, |
203 | type | 222 | type |
204 | }, | 223 | }, |
224 | include: [ | ||
225 | { | ||
226 | model: AccountModel.unscoped(), | ||
227 | required: true, | ||
228 | include: [ | ||
229 | { | ||
230 | model: ActorModel.unscoped(), | ||
231 | required: true, | ||
232 | where: { | ||
233 | serverId: { | ||
234 | [Op.ne]: null | ||
235 | } | ||
236 | } | ||
237 | } | ||
238 | ] | ||
239 | } | ||
240 | ], | ||
205 | transaction: t | 241 | transaction: t |
206 | } | 242 | } |
207 | 243 | ||
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 536b6cb3e..28e5818cd 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts | |||
@@ -472,7 +472,24 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
472 | [Op.lt]: beforeUpdatedAt | 472 | [Op.lt]: beforeUpdatedAt |
473 | }, | 473 | }, |
474 | videoId | 474 | videoId |
475 | } | 475 | }, |
476 | include: [ | ||
477 | { | ||
478 | required: true, | ||
479 | model: AccountModel.unscoped(), | ||
480 | include: [ | ||
481 | { | ||
482 | required: true, | ||
483 | model: ActorModel.unscoped(), | ||
484 | where: { | ||
485 | serverId: { | ||
486 | [Op.ne]: null | ||
487 | } | ||
488 | } | ||
489 | } | ||
490 | ] | ||
491 | } | ||
492 | ] | ||
476 | } | 493 | } |
477 | 494 | ||
478 | return VideoCommentModel.destroy(query) | 495 | return VideoCommentModel.destroy(query) |
diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index fda2d7cea..3bab3c027 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
3 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
4 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 3 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
@@ -8,6 +7,7 @@ import { ActorModel } from '../activitypub/actor' | |||
8 | import { throwIfNotValid } from '../utils' | 7 | import { throwIfNotValid } from '../utils' |
9 | import { VideoModel } from './video' | 8 | import { VideoModel } from './video' |
10 | import { VideoChannelModel } from './video-channel' | 9 | import { VideoChannelModel } from './video-channel' |
10 | import { Op, Transaction } from 'sequelize' | ||
11 | 11 | ||
12 | enum ScopeNames { | 12 | enum ScopeNames { |
13 | FULL = 'FULL', | 13 | FULL = 'FULL', |
@@ -88,7 +88,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
88 | }) | 88 | }) |
89 | Video: VideoModel | 89 | Video: VideoModel |
90 | 90 | ||
91 | static load (actorId: number, videoId: number, t?: Sequelize.Transaction) { | 91 | static load (actorId: number, videoId: number, t?: Transaction) { |
92 | return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({ | 92 | return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({ |
93 | where: { | 93 | where: { |
94 | actorId, | 94 | actorId, |
@@ -98,7 +98,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
98 | }) | 98 | }) |
99 | } | 99 | } |
100 | 100 | ||
101 | static loadByUrl (url: string, t: Sequelize.Transaction) { | 101 | static loadByUrl (url: string, t: Transaction) { |
102 | return VideoShareModel.scope(ScopeNames.FULL).findOne({ | 102 | return VideoShareModel.scope(ScopeNames.FULL).findOne({ |
103 | where: { | 103 | where: { |
104 | url | 104 | url |
@@ -107,7 +107,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
107 | }) | 107 | }) |
108 | } | 108 | } |
109 | 109 | ||
110 | static loadActorsByShare (videoId: number, t: Sequelize.Transaction) { | 110 | static loadActorsByShare (videoId: number, t: Transaction) { |
111 | const query = { | 111 | const query = { |
112 | where: { | 112 | where: { |
113 | videoId | 113 | videoId |
@@ -125,7 +125,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
125 | .then(res => res.map(r => r.Actor)) | 125 | .then(res => res.map(r => r.Actor)) |
126 | } | 126 | } |
127 | 127 | ||
128 | static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Sequelize.Transaction): Bluebird<ActorModel[]> { | 128 | static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Transaction): Bluebird<ActorModel[]> { |
129 | const query = { | 129 | const query = { |
130 | attributes: [], | 130 | attributes: [], |
131 | include: [ | 131 | include: [ |
@@ -163,7 +163,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
163 | .then(res => res.map(r => r.Actor)) | 163 | .then(res => res.map(r => r.Actor)) |
164 | } | 164 | } |
165 | 165 | ||
166 | static loadActorsByVideoChannel (videoChannelId: number, t: Sequelize.Transaction): Bluebird<ActorModel[]> { | 166 | static loadActorsByVideoChannel (videoChannelId: number, t: Transaction): Bluebird<ActorModel[]> { |
167 | const query = { | 167 | const query = { |
168 | attributes: [], | 168 | attributes: [], |
169 | include: [ | 169 | include: [ |
@@ -188,7 +188,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
188 | .then(res => res.map(r => r.Actor)) | 188 | .then(res => res.map(r => r.Actor)) |
189 | } | 189 | } |
190 | 190 | ||
191 | static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Sequelize.Transaction) { | 191 | static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Transaction) { |
192 | const query = { | 192 | const query = { |
193 | offset: start, | 193 | offset: start, |
194 | limit: count, | 194 | limit: count, |
@@ -205,10 +205,21 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
205 | const query = { | 205 | const query = { |
206 | where: { | 206 | where: { |
207 | updatedAt: { | 207 | updatedAt: { |
208 | [Sequelize.Op.lt]: beforeUpdatedAt | 208 | [Op.lt]: beforeUpdatedAt |
209 | }, | 209 | }, |
210 | videoId | 210 | videoId |
211 | } | 211 | }, |
212 | include: [ | ||
213 | { | ||
214 | model: ActorModel.unscoped(), | ||
215 | required: true, | ||
216 | where: { | ||
217 | serverId: { | ||
218 | [ Op.ne ]: null | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | ] | ||
212 | } | 223 | } |
213 | 224 | ||
214 | return VideoShareModel.destroy(query) | 225 | return VideoShareModel.destroy(query) |