From d7d5611c8a23de9b483f0437ad3469afef7b8805 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Nov 2017 15:55:01 +0100 Subject: Federate video update --- server/models/video/video-share.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'server/models/video/video-share.ts') diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index 358491fd2..22ac31a4a 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts @@ -1,9 +1,10 @@ import * as Sequelize from 'sequelize' import { addMethodsToModel } from '../utils' -import { VideoShareAttributes, VideoShareInstance } from './video-share-interface' +import { VideoShareAttributes, VideoShareInstance, VideoShareMethods } from './video-share-interface' let VideoShare: Sequelize.Model +let loadAccountsByShare: VideoShareMethods.LoadAccountsByShare export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { VideoShare = sequelize.define('VideoShare', @@ -21,7 +22,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da ) const classMethods = [ - associate + associate, + loadAccountsByShare ] addMethodsToModel(VideoShare, classMethods) @@ -47,3 +49,20 @@ function associate (models) { onDelete: 'cascade' }) } + +loadAccountsByShare = function (videoId: number) { + const query = { + where: { + videoId + }, + include: [ + { + model: VideoShare['sequelize'].models.Account, + required: true + } + ] + } + + return VideoShare.findAll(query) + .then(res => res.map(r => r.Account)) +} -- cgit v1.2.3