1 import { database as db } from '../initializers'
2 import { UserInstance } from '../models'
3 import { addVideoAuthorToFriends } from './friends'
4 import { createVideoChannel } from './video-channel'
6 function createUserAuthorAndChannel (user: UserInstance, validateUser = true) {
7 return db.sequelize.transaction(t => {
10 validate: validateUser
13 return user.save(userOptions)
15 const author = db.Author.build({
17 podId: null, // It is our pod
21 return author.save({ transaction: t })
22 .then(author => ({ author, user }))
24 .then(({ author, user }) => {
25 const remoteVideoAuthor = author.toAddRemoteJSON()
27 // Now we'll add the video channel's meta data to our friends
28 return addVideoAuthorToFriends(remoteVideoAuthor, t)
29 .then(() => ({ author, user }))
31 .then(({ author, user }) => {
32 const videoChannelInfo = {
33 name: `Default ${user.username} channel`
36 return createVideoChannel(videoChannelInfo, author, t)
37 .then(videoChannel => ({ author, user, videoChannel }))
42 // ---------------------------------------------------------------------------
45 createUserAuthorAndChannel