diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-07-05 13:26:25 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-07-05 14:14:16 +0200 |
commit | 6fcd19ba737f1f5614a56c6925adb882dea43b8d (patch) | |
tree | 3365a96d82bc7f00ae504a568725c8e914150cf8 /server/middlewares/validators/pods.ts | |
parent | 5fe7e898316e18369c3e1aba307b55077adc7bfb (diff) | |
download | PeerTube-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/middlewares/validators/pods.ts')
-rw-r--r-- | server/middlewares/validators/pods.ts | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/server/middlewares/validators/pods.ts b/server/middlewares/validators/pods.ts index d8eb90168..da7fc2bd6 100644 --- a/server/middlewares/validators/pods.ts +++ b/server/middlewares/validators/pods.ts | |||
@@ -19,19 +19,19 @@ function makeFriendsValidator (req: express.Request, res: express.Response, next | |||
19 | logger.debug('Checking makeFriends parameters', { parameters: req.body }) | 19 | logger.debug('Checking makeFriends parameters', { parameters: req.body }) |
20 | 20 | ||
21 | checkErrors(req, res, function () { | 21 | checkErrors(req, res, function () { |
22 | hasFriends(function (err, heHasFriends) { | 22 | hasFriends() |
23 | if (err) { | 23 | .then(heHasFriends => { |
24 | if (heHasFriends === true) { | ||
25 | // We need to quit our friends before make new ones | ||
26 | return res.sendStatus(409) | ||
27 | } | ||
28 | |||
29 | return next() | ||
30 | }) | ||
31 | .catch(err => { | ||
24 | logger.error('Cannot know if we have friends.', { error: err }) | 32 | logger.error('Cannot know if we have friends.', { error: err }) |
25 | res.sendStatus(500) | 33 | res.sendStatus(500) |
26 | } | 34 | }) |
27 | |||
28 | if (heHasFriends === true) { | ||
29 | // We need to quit our friends before make new ones | ||
30 | return res.sendStatus(409) | ||
31 | } | ||
32 | |||
33 | return next() | ||
34 | }) | ||
35 | }) | 35 | }) |
36 | } | 36 | } |
37 | 37 | ||
@@ -42,19 +42,19 @@ function podsAddValidator (req: express.Request, res: express.Response, next: ex | |||
42 | logger.debug('Checking podsAdd parameters', { parameters: req.body }) | 42 | logger.debug('Checking podsAdd parameters', { parameters: req.body }) |
43 | 43 | ||
44 | checkErrors(req, res, function () { | 44 | checkErrors(req, res, function () { |
45 | db.Pod.loadByHost(req.body.host, function (err, pod) { | 45 | db.Pod.loadByHost(req.body.host) |
46 | if (err) { | 46 | .then(pod => { |
47 | // Pod with this host already exists | ||
48 | if (pod) { | ||
49 | return res.sendStatus(409) | ||
50 | } | ||
51 | |||
52 | return next() | ||
53 | }) | ||
54 | .catch(err => { | ||
47 | logger.error('Cannot load pod by host.', { error: err }) | 55 | logger.error('Cannot load pod by host.', { error: err }) |
48 | res.sendStatus(500) | 56 | res.sendStatus(500) |
49 | } | 57 | }) |
50 | |||
51 | // Pod with this host already exists | ||
52 | if (pod) { | ||
53 | return res.sendStatus(409) | ||
54 | } | ||
55 | |||
56 | return next() | ||
57 | }) | ||
58 | }) | 58 | }) |
59 | } | 59 | } |
60 | 60 | ||