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