diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/index.ts | 2 | ||||
-rw-r--r-- | server/models/video/video-channel-share-interface.ts | 27 | ||||
-rw-r--r-- | server/models/video/video-channel-share.ts | 49 | ||||
-rw-r--r-- | server/models/video/video-share-interface.ts | 25 | ||||
-rw-r--r-- | server/models/video/video-share.ts | 49 | ||||
-rw-r--r-- | server/models/video/video.ts | 11 |
6 files changed, 152 insertions, 11 deletions
diff --git a/server/models/video/index.ts b/server/models/video/index.ts index 20d97931f..e17bbfab4 100644 --- a/server/models/video/index.ts +++ b/server/models/video/index.ts | |||
@@ -5,3 +5,5 @@ export * from './video-channel-interface' | |||
5 | export * from './video-tag-interface' | 5 | export * from './video-tag-interface' |
6 | export * from './video-file-interface' | 6 | export * from './video-file-interface' |
7 | export * from './video-interface' | 7 | export * from './video-interface' |
8 | export * from './video-share-interface' | ||
9 | export * from './video-channel-share-interface' | ||
diff --git a/server/models/video/video-channel-share-interface.ts b/server/models/video/video-channel-share-interface.ts new file mode 100644 index 000000000..9ac6d7b23 --- /dev/null +++ b/server/models/video/video-channel-share-interface.ts | |||
@@ -0,0 +1,27 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import { AccountInstance } from '../account/account-interface' | ||
3 | import { VideoChannelInstance } from './video-channel-interface' | ||
4 | |||
5 | export namespace VideoChannelShareMethods { | ||
6 | } | ||
7 | |||
8 | export interface VideoChannelShareClass { | ||
9 | } | ||
10 | |||
11 | export interface VideoChannelShareAttributes { | ||
12 | accountId: number | ||
13 | videoChannelId: number | ||
14 | } | ||
15 | |||
16 | export interface VideoChannelShareInstance | ||
17 | extends VideoChannelShareClass, VideoChannelShareAttributes, Sequelize.Instance<VideoChannelShareAttributes> { | ||
18 | id: number | ||
19 | createdAt: Date | ||
20 | updatedAt: Date | ||
21 | |||
22 | Account?: AccountInstance | ||
23 | VideoChannel?: VideoChannelInstance | ||
24 | } | ||
25 | |||
26 | export interface VideoChannelShareModel | ||
27 | extends VideoChannelShareClass, Sequelize.Model<VideoChannelShareInstance, VideoChannelShareAttributes> {} | ||
diff --git a/server/models/video/video-channel-share.ts b/server/models/video/video-channel-share.ts new file mode 100644 index 000000000..b6199279f --- /dev/null +++ b/server/models/video/video-channel-share.ts | |||
@@ -0,0 +1,49 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | |||
3 | import { addMethodsToModel } from '../utils' | ||
4 | import { VideoChannelShareAttributes, VideoChannelShareInstance } from './video-channel-share-interface' | ||
5 | |||
6 | let VideoChannelShare: Sequelize.Model<VideoChannelShareInstance, VideoChannelShareAttributes> | ||
7 | |||
8 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { | ||
9 | VideoChannelShare = sequelize.define<VideoChannelShareInstance, VideoChannelShareAttributes>('VideoChannelShare', | ||
10 | { }, | ||
11 | { | ||
12 | indexes: [ | ||
13 | { | ||
14 | fields: [ 'accountId' ] | ||
15 | }, | ||
16 | { | ||
17 | fields: [ 'videoChannelId' ] | ||
18 | } | ||
19 | ] | ||
20 | } | ||
21 | ) | ||
22 | |||
23 | const classMethods = [ | ||
24 | associate | ||
25 | ] | ||
26 | addMethodsToModel(VideoChannelShare, classMethods) | ||
27 | |||
28 | return VideoChannelShare | ||
29 | } | ||
30 | |||
31 | // ------------------------------ METHODS ------------------------------ | ||
32 | |||
33 | function associate (models) { | ||
34 | VideoChannelShare.belongsTo(models.Account, { | ||
35 | foreignKey: { | ||
36 | name: 'accountId', | ||
37 | allowNull: false | ||
38 | }, | ||
39 | onDelete: 'cascade' | ||
40 | }) | ||
41 | |||
42 | VideoChannelShare.belongsTo(models.VideoChannel, { | ||
43 | foreignKey: { | ||
44 | name: 'videoChannelId', | ||
45 | allowNull: true | ||
46 | }, | ||
47 | onDelete: 'cascade' | ||
48 | }) | ||
49 | } | ||
diff --git a/server/models/video/video-share-interface.ts b/server/models/video/video-share-interface.ts new file mode 100644 index 000000000..7928b9a9c --- /dev/null +++ b/server/models/video/video-share-interface.ts | |||
@@ -0,0 +1,25 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import { AccountInstance } from '../account/account-interface' | ||
3 | import { VideoInstance } from './video-interface' | ||
4 | |||
5 | export namespace VideoShareMethods { | ||
6 | } | ||
7 | |||
8 | export interface VideoShareClass { | ||
9 | } | ||
10 | |||
11 | export interface VideoShareAttributes { | ||
12 | accountId: number | ||
13 | videoId: number | ||
14 | } | ||
15 | |||
16 | export interface VideoShareInstance extends VideoShareClass, VideoShareAttributes, Sequelize.Instance<VideoShareAttributes> { | ||
17 | id: number | ||
18 | createdAt: Date | ||
19 | updatedAt: Date | ||
20 | |||
21 | Account?: AccountInstance | ||
22 | Video?: VideoInstance | ||
23 | } | ||
24 | |||
25 | export interface VideoShareModel extends VideoShareClass, Sequelize.Model<VideoShareInstance, VideoShareAttributes> {} | ||
diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts new file mode 100644 index 000000000..358491fd2 --- /dev/null +++ b/server/models/video/video-share.ts | |||
@@ -0,0 +1,49 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | |||
3 | import { addMethodsToModel } from '../utils' | ||
4 | import { VideoShareAttributes, VideoShareInstance } from './video-share-interface' | ||
5 | |||
6 | let VideoShare: Sequelize.Model<VideoShareInstance, VideoShareAttributes> | ||
7 | |||
8 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { | ||
9 | VideoShare = sequelize.define<VideoShareInstance, VideoShareAttributes>('VideoShare', | ||
10 | { }, | ||
11 | { | ||
12 | indexes: [ | ||
13 | { | ||
14 | fields: [ 'accountId' ] | ||
15 | }, | ||
16 | { | ||
17 | fields: [ 'videoId' ] | ||
18 | } | ||
19 | ] | ||
20 | } | ||
21 | ) | ||
22 | |||
23 | const classMethods = [ | ||
24 | associate | ||
25 | ] | ||
26 | addMethodsToModel(VideoShare, classMethods) | ||
27 | |||
28 | return VideoShare | ||
29 | } | ||
30 | |||
31 | // ------------------------------ METHODS ------------------------------ | ||
32 | |||
33 | function associate (models) { | ||
34 | VideoShare.belongsTo(models.Account, { | ||
35 | foreignKey: { | ||
36 | name: 'accountId', | ||
37 | allowNull: false | ||
38 | }, | ||
39 | onDelete: 'cascade' | ||
40 | }) | ||
41 | |||
42 | VideoShare.belongsTo(models.Video, { | ||
43 | foreignKey: { | ||
44 | name: 'videoId', | ||
45 | allowNull: true | ||
46 | }, | ||
47 | onDelete: 'cascade' | ||
48 | }) | ||
49 | } | ||
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index b00081f25..480e54276 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -253,9 +253,6 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da | |||
253 | }, | 253 | }, |
254 | { | 254 | { |
255 | fields: [ 'channelId' ] | 255 | fields: [ 'channelId' ] |
256 | }, | ||
257 | { | ||
258 | fields: [ 'parentId' ] | ||
259 | } | 256 | } |
260 | ], | 257 | ], |
261 | hooks: { | 258 | hooks: { |
@@ -329,14 +326,6 @@ function associate (models) { | |||
329 | onDelete: 'cascade' | 326 | onDelete: 'cascade' |
330 | }) | 327 | }) |
331 | 328 | ||
332 | Video.belongsTo(models.Video, { | ||
333 | foreignKey: { | ||
334 | name: 'parentId', | ||
335 | allowNull: true | ||
336 | }, | ||
337 | onDelete: 'cascade' | ||
338 | }) | ||
339 | |||
340 | Video.belongsToMany(models.Tag, { | 329 | Video.belongsToMany(models.Tag, { |
341 | foreignKey: 'videoId', | 330 | foreignKey: 'videoId', |
342 | through: models.VideoTag, | 331 | through: models.VideoTag, |