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