aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/user.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/user.ts')
-rw-r--r--server/lib/user.ts52
1 files changed, 24 insertions, 28 deletions
diff --git a/server/lib/user.ts b/server/lib/user.ts
index 8609e72d8..a92f4777b 100644
--- a/server/lib/user.ts
+++ b/server/lib/user.ts
@@ -3,40 +3,36 @@ import { UserInstance } from '../models'
3import { addVideoAuthorToFriends } from './friends' 3import { addVideoAuthorToFriends } from './friends'
4import { createVideoChannel } from './video-channel' 4import { createVideoChannel } from './video-channel'
5 5
6function createUserAuthorAndChannel (user: UserInstance, validateUser = true) { 6async function createUserAuthorAndChannel (user: UserInstance, validateUser = true) {
7 return db.sequelize.transaction(t => { 7 const res = await db.sequelize.transaction(async t => {
8 const userOptions = { 8 const userOptions = {
9 transaction: t, 9 transaction: t,
10 validate: validateUser 10 validate: validateUser
11 } 11 }
12 12
13 return user.save(userOptions) 13 const userCreated = await user.save(userOptions)
14 .then(user => { 14 const authorInstance = db.Author.build({
15 const author = db.Author.build({ 15 name: userCreated.username,
16 name: user.username, 16 podId: null, // It is our pod
17 podId: null, // It is our pod 17 userId: userCreated.id
18 userId: user.id 18 })
19 }) 19
20 20 const authorCreated = await authorInstance.save({ transaction: t })
21 return author.save({ transaction: t }) 21
22 .then(author => ({ author, user })) 22 const remoteVideoAuthor = authorCreated.toAddRemoteJSON()
23 }) 23
24 .then(({ author, user }) => { 24 // Now we'll add the video channel's meta data to our friends
25 const remoteVideoAuthor = author.toAddRemoteJSON() 25 const author = await addVideoAuthorToFriends(remoteVideoAuthor, t)
26 26
27 // Now we'll add the video channel's meta data to our friends 27 const videoChannelInfo = {
28 return addVideoAuthorToFriends(remoteVideoAuthor, t) 28 name: `Default ${userCreated.username} channel`
29 .then(() => ({ author, user })) 29 }
30 }) 30 const videoChannel = await createVideoChannel(videoChannelInfo, authorCreated, t)
31 .then(({ author, user }) => { 31
32 const videoChannelInfo = { 32 return { author, videoChannel }
33 name: `Default ${user.username} channel`
34 }
35
36 return createVideoChannel(videoChannelInfo, author, t)
37 .then(videoChannel => ({ author, user, videoChannel }))
38 })
39 }) 33 })
34
35 return res
40} 36}
41 37
42// --------------------------------------------------------------------------- 38// ---------------------------------------------------------------------------