diff options
Diffstat (limited to 'server/models/video/video-channel-share.ts')
-rw-r--r-- | server/models/video/video-channel-share.ts | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/server/models/video/video-channel-share.ts b/server/models/video/video-channel-share.ts index b6199279f..01f84c806 100644 --- a/server/models/video/video-channel-share.ts +++ b/server/models/video/video-channel-share.ts | |||
@@ -1,9 +1,10 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | 2 | ||
3 | import { addMethodsToModel } from '../utils' | 3 | import { addMethodsToModel } from '../utils' |
4 | import { VideoChannelShareAttributes, VideoChannelShareInstance } from './video-channel-share-interface' | 4 | import { VideoChannelShareAttributes, VideoChannelShareInstance, VideoChannelShareMethods } from './video-channel-share-interface' |
5 | 5 | ||
6 | let VideoChannelShare: Sequelize.Model<VideoChannelShareInstance, VideoChannelShareAttributes> | 6 | let VideoChannelShare: Sequelize.Model<VideoChannelShareInstance, VideoChannelShareAttributes> |
7 | let loadAccountsByShare: VideoChannelShareMethods.LoadAccountsByShare | ||
7 | 8 | ||
8 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { | 9 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { |
9 | VideoChannelShare = sequelize.define<VideoChannelShareInstance, VideoChannelShareAttributes>('VideoChannelShare', | 10 | VideoChannelShare = sequelize.define<VideoChannelShareInstance, VideoChannelShareAttributes>('VideoChannelShare', |
@@ -21,7 +22,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da | |||
21 | ) | 22 | ) |
22 | 23 | ||
23 | const classMethods = [ | 24 | const classMethods = [ |
24 | associate | 25 | associate, |
26 | loadAccountsByShare | ||
25 | ] | 27 | ] |
26 | addMethodsToModel(VideoChannelShare, classMethods) | 28 | addMethodsToModel(VideoChannelShare, classMethods) |
27 | 29 | ||
@@ -47,3 +49,20 @@ function associate (models) { | |||
47 | onDelete: 'cascade' | 49 | onDelete: 'cascade' |
48 | }) | 50 | }) |
49 | } | 51 | } |
52 | |||
53 | loadAccountsByShare = function (videoChannelId: number) { | ||
54 | const query = { | ||
55 | where: { | ||
56 | videoChannelId | ||
57 | }, | ||
58 | include: [ | ||
59 | { | ||
60 | model: VideoChannelShare['sequelize'].models.Account, | ||
61 | required: true | ||
62 | } | ||
63 | ] | ||
64 | } | ||
65 | |||
66 | return VideoChannelShare.findAll(query) | ||
67 | .then(res => res.map(r => r.Account)) | ||
68 | } | ||