aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/author.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-05 13:26:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-05 14:14:16 +0200
commit6fcd19ba737f1f5614a56c6925adb882dea43b8d (patch)
tree3365a96d82bc7f00ae504a568725c8e914150cf8 /server/models/video/author.ts
parent5fe7e898316e18369c3e1aba307b55077adc7bfb (diff)
downloadPeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.gz
PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.zst
PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.zip
Move to promises
Closes https://github.com/Chocobozzz/PeerTube/issues/74
Diffstat (limited to 'server/models/video/author.ts')
-rw-r--r--server/models/video/author.ts23
1 files changed, 5 insertions, 18 deletions
diff --git a/server/models/video/author.ts b/server/models/video/author.ts
index 4a115e328..3222c4834 100644
--- a/server/models/video/author.ts
+++ b/server/models/video/author.ts
@@ -4,7 +4,6 @@ import { isUserUsernameValid } from '../../helpers'
4 4
5import { addMethodsToModel } from '../utils' 5import { addMethodsToModel } from '../utils'
6import { 6import {
7 AuthorClass,
8 AuthorInstance, 7 AuthorInstance,
9 AuthorAttributes, 8 AuthorAttributes,
10 9
@@ -74,30 +73,18 @@ function associate (models) {
74 }) 73 })
75} 74}
76 75
77findOrCreateAuthor = function ( 76findOrCreateAuthor = function (name: string, podId: number, userId: number, transaction: Sequelize.Transaction) {
78 name: string,
79 podId: number,
80 userId: number,
81 transaction: Sequelize.Transaction,
82 callback: AuthorMethods.FindOrCreateAuthorCallback
83) {
84 const author = { 77 const author = {
85 name, 78 name,
86 podId, 79 podId,
87 userId 80 userId
88 } 81 }
89 82
90 const query: any = { 83 const query: Sequelize.FindOrInitializeOptions<AuthorAttributes> = {
91 where: author, 84 where: author,
92 defaults: author 85 defaults: author,
86 transaction
93 } 87 }
94 88
95 if (transaction !== null) query.transaction = transaction 89 return Author.findOrCreate(query).then(([ authorInstance ]) => authorInstance)
96
97 Author.findOrCreate(query).asCallback(function (err, result) {
98 if (err) return callback(err)
99
100 // [ instance, wasCreated ]
101 return callback(null, result[0])
102 })
103} 90}