]>
Commit | Line | Data |
---|---|---|
72c7248b C |
1 | import { database as db } from '../initializers' |
2 | import { UserInstance } from '../models' | |
e4f97bab | 3 | import { addVideoAccountToFriends } from './friends' |
72c7248b C |
4 | import { createVideoChannel } from './video-channel' |
5 | ||
e4f97bab | 6 | async 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 | ||
40 | export { | |
e4f97bab | 41 | createUserAccountAndChannel |
72c7248b | 42 | } |