aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-24 09:44:36 +0200
committerChocobozzz <me@florianbigard.com>2019-04-24 16:26:21 +0200
commitb876eaf11a1ed9683664d94767ca684ba5b77753 (patch)
treef226897dcccae2648532095954f57c2058ed1834 /server/models
parentdc8527376482293c87fc6f30027d626f58a1197b (diff)
downloadPeerTube-b876eaf11a1ed9683664d94767ca684ba5b77753.tar.gz
PeerTube-b876eaf11a1ed9683664d94767ca684ba5b77753.tar.zst
PeerTube-b876eaf11a1ed9683664d94767ca684ba5b77753.zip
Fix ownership changes
Diffstat (limited to 'server/models')
-rw-r--r--server/models/video/video-change-ownership.ts36
1 files changed, 20 insertions, 16 deletions
diff --git a/server/models/video/video-change-ownership.ts b/server/models/video/video-change-ownership.ts
index 171d4574d..b545a2f8c 100644
--- a/server/models/video/video-change-ownership.ts
+++ b/server/models/video/video-change-ownership.ts
@@ -1,30 +1,30 @@
1import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' 1import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
2import { AccountModel } from '../account/account' 2import { AccountModel } from '../account/account'
3import { VideoModel } from './video' 3import { ScopeNames as VideoScopeNames, VideoModel } from './video'
4import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos' 4import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos'
5import { getSort } from '../utils' 5import { getSort } from '../utils'
6import { VideoFileModel } from './video-file'
7 6
8enum ScopeNames { 7enum ScopeNames {
9 FULL = 'FULL' 8 WITH_ACCOUNTS = 'WITH_ACCOUNTS',
9 WITH_VIDEO = 'WITH_VIDEO'
10} 10}
11 11
12@Table({ 12@Table({
13 tableName: 'videoChangeOwnership', 13 tableName: 'videoChangeOwnership',
14 indexes: [ 14 indexes: [
15 { 15 {
16 fields: ['videoId'] 16 fields: [ 'videoId' ]
17 }, 17 },
18 { 18 {
19 fields: ['initiatorAccountId'] 19 fields: [ 'initiatorAccountId' ]
20 }, 20 },
21 { 21 {
22 fields: ['nextOwnerAccountId'] 22 fields: [ 'nextOwnerAccountId' ]
23 } 23 }
24 ] 24 ]
25}) 25})
26@Scopes(() => ({ 26@Scopes(() => ({
27 [ScopeNames.FULL]: { 27 [ScopeNames.WITH_ACCOUNTS]: {
28 include: [ 28 include: [
29 { 29 {
30 model: AccountModel, 30 model: AccountModel,
@@ -35,13 +35,14 @@ enum ScopeNames {
35 model: AccountModel, 35 model: AccountModel,
36 as: 'NextOwner', 36 as: 'NextOwner',
37 required: true 37 required: true
38 }, 38 }
39 ]
40 },
41 [ScopeNames.WITH_VIDEO]: {
42 include: [
39 { 43 {
40 model: VideoModel, 44 model: VideoModel.scope([ VideoScopeNames.WITH_THUMBNAILS, VideoScopeNames.WITH_FILES ]),
41 required: true, 45 required: true
42 include: [
43 { model: VideoFileModel }
44 ]
45 } 46 }
46 ] 47 ]
47 } 48 }
@@ -105,12 +106,15 @@ export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel>
105 } 106 }
106 } 107 }
107 108
108 return VideoChangeOwnershipModel.scope(ScopeNames.FULL).findAndCountAll(query) 109 return Promise.all([
109 .then(({ rows, count }) => ({ total: count, data: rows })) 110 VideoChangeOwnershipModel.scope(ScopeNames.WITH_ACCOUNTS).count(query),
111 VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ]).findAll(query)
112 ]).then(([ count, rows ]) => ({ total: count, data: rows }))
110 } 113 }
111 114
112 static load (id: number) { 115 static load (id: number) {
113 return VideoChangeOwnershipModel.scope(ScopeNames.FULL).findByPk(id) 116 return VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ])
117 .findByPk(id)
114 } 118 }
115 119
116 toFormattedJSON (): VideoChangeOwnership { 120 toFormattedJSON (): VideoChangeOwnership {