1 import * as Sequelize from 'sequelize'
3 import { addVideoChannelToFriends } from './friends'
4 import { database as db } from '../initializers'
5 import { AuthorInstance } from '../models'
6 import { VideoChannelCreate } from '../../shared/models'
8 function createVideoChannel (videoChannelInfo: VideoChannelCreate, author: AuthorInstance, t: Sequelize.Transaction) {
9 let videoChannelUUID = ''
11 const videoChannelData = {
12 name: videoChannelInfo.name,
13 description: videoChannelInfo.description,
18 const videoChannel = db.VideoChannel.build(videoChannelData)
19 const options = { transaction: t }
21 return videoChannel.save(options)
22 .then(videoChannelCreated => {
23 // Do not forget to add Author information to the created video channel
24 videoChannelCreated.Author = author
25 videoChannelUUID = videoChannelCreated.uuid
27 return videoChannelCreated
29 .then(videoChannel => {
30 const remoteVideoChannel = videoChannel.toAddRemoteJSON()
32 // Now we'll add the video channel's meta data to our friends
33 return addVideoChannelToFriends(remoteVideoChannel, t)
35 .then(() => videoChannelUUID) // Return video channel UUID
38 // ---------------------------------------------------------------------------