1 import { database as db } from '../initializers'
2 import { UserInstance } from '../models'
3 import { addVideoAccountToFriends } from './friends'
4 import { createVideoChannel } from './video-channel'
6 async function createUserAccountAndChannel (user: UserInstance, validateUser = true) {
7 const res = await db.sequelize.transaction(async t => {
10 validate: validateUser
13 const userCreated = await user.save(userOptions)
14 const accountInstance = db.Account.build({
15 name: userCreated.username,
16 podId: null, // It is our pod
17 userId: userCreated.id
20 const accountCreated = await accountInstance.save({ transaction: t })
22 const remoteVideoAccount = accountCreated.toAddRemoteJSON()
24 // Now we'll add the video channel's meta data to our friends
25 const account = await addVideoAccountToFriends(remoteVideoAccount, t)
27 const videoChannelInfo = {
28 name: `Default ${userCreated.username} channel`
30 const videoChannel = await createVideoChannel(videoChannelInfo, accountCreated, t)
32 return { account, videoChannel }
38 // ---------------------------------------------------------------------------
41 createUserAccountAndChannel