1 import { database as db } from '../initializers'
2 import { UserInstance } from '../models'
3 import { addVideoAuthorToFriends } from './friends'
4 import { createVideoChannel } from './video-channel'
6 async function createUserAuthorAndChannel (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 authorInstance = db.Author.build({
15 name: userCreated.username,
16 podId: null, // It is our pod
17 userId: userCreated.id
20 const authorCreated = await authorInstance.save({ transaction: t })
22 const remoteVideoAuthor = authorCreated.toAddRemoteJSON()
24 // Now we'll add the video channel's meta data to our friends
25 const author = await addVideoAuthorToFriends(remoteVideoAuthor, t)
27 const videoChannelInfo = {
28 name: `Default ${userCreated.username} channel`
30 const videoChannel = await createVideoChannel(videoChannelInfo, authorCreated, t)
32 return { author, videoChannel }
38 // ---------------------------------------------------------------------------
41 createUserAuthorAndChannel