]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/user.ts
Remove references to author
[github/Chocobozzz/PeerTube.git] / server / lib / user.ts
CommitLineData
72c7248b
C
1import { database as db } from '../initializers'
2import { UserInstance } from '../models'
e4f97bab 3import { addVideoAccountToFriends } from './friends'
72c7248b
C
4import { createVideoChannel } from './video-channel'
5
e4f97bab 6async function createUserAccountAndChannel (user: UserInstance, validateUser = true) {
f5028693 7 const res = await db.sequelize.transaction(async t => {
72c7248b
C
8 const userOptions = {
9 transaction: t,
10 validate: validateUser
11 }
12
f5028693 13 const userCreated = await user.save(userOptions)
e4f97bab 14 const accountInstance = db.Account.build({
f5028693
C
15 name: userCreated.username,
16 podId: null, // It is our pod
17 userId: userCreated.id
18 })
19
e4f97bab 20 const accountCreated = await accountInstance.save({ transaction: t })
f5028693 21
e4f97bab 22 const remoteVideoAccount = accountCreated.toAddRemoteJSON()
f5028693
C
23
24 // Now we'll add the video channel's meta data to our friends
e4f97bab 25 const account = await addVideoAccountToFriends(remoteVideoAccount, t)
f5028693
C
26
27 const videoChannelInfo = {
28 name: `Default ${userCreated.username} channel`
29 }
e4f97bab 30 const videoChannel = await createVideoChannel(videoChannelInfo, accountCreated, t)
f5028693 31
e4f97bab 32 return { account, videoChannel }
72c7248b 33 })
f5028693
C
34
35 return res
72c7248b
C
36}
37
38// ---------------------------------------------------------------------------
39
40export {
e4f97bab 41 createUserAccountAndChannel
72c7248b 42}