aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-channel-share.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video-channel-share.ts')
-rw-r--r--server/models/video/video-channel-share.ts43
1 files changed, 30 insertions, 13 deletions
diff --git a/server/models/video/video-channel-share.ts b/server/models/video/video-channel-share.ts
index cdba32fcd..f5b7a7cd5 100644
--- a/server/models/video/video-channel-share.ts
+++ b/server/models/video/video-channel-share.ts
@@ -1,8 +1,35 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' 2import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
3import { AccountModel } from '../account/account' 3import { AccountModel } from '../account/account'
4import { VideoChannelModel } from './video-channel' 4import { VideoChannelModel } from './video-channel'
5 5
6enum ScopeNames {
7 FULL = 'FULL',
8 WITH_ACCOUNT = 'WITH_ACCOUNT'
9}
10
11@Scopes({
12 [ScopeNames.FULL]: {
13 include: [
14 {
15 model: () => AccountModel,
16 required: true
17 },
18 {
19 model: () => VideoChannelModel,
20 required: true
21 }
22 ]
23 },
24 [ScopeNames.WITH_ACCOUNT]: {
25 include: [
26 {
27 model: () => AccountModel,
28 required: true
29 }
30 ]
31 }
32})
6@Table({ 33@Table({
7 tableName: 'videoChannelShare', 34 tableName: 'videoChannelShare',
8 indexes: [ 35 indexes: [
@@ -46,15 +73,11 @@ export class VideoChannelShareModel extends Model<VideoChannelShareModel> {
46 VideoChannel: VideoChannelModel 73 VideoChannel: VideoChannelModel
47 74
48 static load (accountId: number, videoChannelId: number, t: Sequelize.Transaction) { 75 static load (accountId: number, videoChannelId: number, t: Sequelize.Transaction) {
49 return VideoChannelShareModel.findOne({ 76 return VideoChannelShareModel.scope(ScopeNames.FULL).findOne({
50 where: { 77 where: {
51 accountId, 78 accountId,
52 videoChannelId 79 videoChannelId
53 }, 80 },
54 include: [
55 AccountModel,
56 VideoChannelModel
57 ],
58 transaction: t 81 transaction: t
59 }) 82 })
60 } 83 }
@@ -64,16 +87,10 @@ export class VideoChannelShareModel extends Model<VideoChannelShareModel> {
64 where: { 87 where: {
65 videoChannelId 88 videoChannelId
66 }, 89 },
67 include: [
68 {
69 model: AccountModel,
70 required: true
71 }
72 ],
73 transaction: t 90 transaction: t
74 } 91 }
75 92
76 return VideoChannelShareModel.findAll(query) 93 return VideoChannelShareModel.scope(ScopeNames.WITH_ACCOUNT).findAll(query)
77 .then(res => res.map(r => r.Account)) 94 .then(res => res.map(r => r.Account))
78 } 95 }
79} 96}