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.ts96
1 files changed, 0 insertions, 96 deletions
diff --git a/server/models/video/video-channel-share.ts b/server/models/video/video-channel-share.ts
deleted file mode 100644
index f5b7a7cd5..000000000
--- a/server/models/video/video-channel-share.ts
+++ /dev/null
@@ -1,96 +0,0 @@
1import * as Sequelize from 'sequelize'
2import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
3import { AccountModel } from '../account/account'
4import { VideoChannelModel } from './video-channel'
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})
33@Table({
34 tableName: 'videoChannelShare',
35 indexes: [
36 {
37 fields: [ 'accountId' ]
38 },
39 {
40 fields: [ 'videoChannelId' ]
41 }
42 ]
43})
44export class VideoChannelShareModel extends Model<VideoChannelShareModel> {
45 @CreatedAt
46 createdAt: Date
47
48 @UpdatedAt
49 updatedAt: Date
50
51 @ForeignKey(() => AccountModel)
52 @Column
53 accountId: number
54
55 @BelongsTo(() => AccountModel, {
56 foreignKey: {
57 allowNull: false
58 },
59 onDelete: 'cascade'
60 })
61 Account: AccountModel
62
63 @ForeignKey(() => VideoChannelModel)
64 @Column
65 videoChannelId: number
66
67 @BelongsTo(() => VideoChannelModel, {
68 foreignKey: {
69 allowNull: false
70 },
71 onDelete: 'cascade'
72 })
73 VideoChannel: VideoChannelModel
74
75 static load (accountId: number, videoChannelId: number, t: Sequelize.Transaction) {
76 return VideoChannelShareModel.scope(ScopeNames.FULL).findOne({
77 where: {
78 accountId,
79 videoChannelId
80 },
81 transaction: t
82 })
83 }
84
85 static loadAccountsByShare (videoChannelId: number, t: Sequelize.Transaction) {
86 const query = {
87 where: {
88 videoChannelId
89 },
90 transaction: t
91 }
92
93 return VideoChannelShareModel.scope(ScopeNames.WITH_ACCOUNT).findAll(query)
94 .then(res => res.map(r => r.Account))
95 }
96}