aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/users.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/users.ts')
-rw-r--r--server/middlewares/validators/users.ts52
1 files changed, 26 insertions, 26 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index b7b9ef370..c06735047 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -13,16 +13,16 @@ function usersAddValidator (req: express.Request, res: express.Response, next: e
13 logger.debug('Checking usersAdd parameters', { parameters: req.body }) 13 logger.debug('Checking usersAdd parameters', { parameters: req.body })
14 14
15 checkErrors(req, res, function () { 15 checkErrors(req, res, function () {
16 db.User.loadByUsernameOrEmail(req.body.username, req.body.email, function (err, user) { 16 db.User.loadByUsernameOrEmail(req.body.username, req.body.email)
17 if (err) { 17 .then(user => {
18 if (user) return res.status(409).send('User already exists.')
19
20 next()
21 })
22 .catch(err => {
18 logger.error('Error in usersAdd request validator.', { error: err }) 23 logger.error('Error in usersAdd request validator.', { error: err })
19 return res.sendStatus(500) 24 return res.sendStatus(500)
20 } 25 })
21
22 if (user) return res.status(409).send('User already exists.')
23
24 next()
25 })
26 }) 26 })
27} 27}
28 28
@@ -32,18 +32,18 @@ function usersRemoveValidator (req: express.Request, res: express.Response, next
32 logger.debug('Checking usersRemove parameters', { parameters: req.params }) 32 logger.debug('Checking usersRemove parameters', { parameters: req.params })
33 33
34 checkErrors(req, res, function () { 34 checkErrors(req, res, function () {
35 db.User.loadById(req.params.id, function (err, user) { 35 db.User.loadById(req.params.id)
36 if (err) { 36 .then(user => {
37 logger.error('Error in usersRemove request validator.', { error: err }) 37 if (!user) return res.status(404).send('User not found')
38 return res.sendStatus(500)
39 }
40
41 if (!user) return res.status(404).send('User not found')
42 38
43 if (user.username === 'root') return res.status(400).send('Cannot remove the root user') 39 if (user.username === 'root') return res.status(400).send('Cannot remove the root user')
44 40
45 next() 41 next()
46 }) 42 })
43 .catch(err => {
44 logger.error('Error in usersRemove request validator.', { error: err })
45 return res.sendStatus(500)
46 })
47 }) 47 })
48} 48}
49 49
@@ -64,16 +64,16 @@ function usersVideoRatingValidator (req: express.Request, res: express.Response,
64 logger.debug('Checking usersVideoRating parameters', { parameters: req.params }) 64 logger.debug('Checking usersVideoRating parameters', { parameters: req.params })
65 65
66 checkErrors(req, res, function () { 66 checkErrors(req, res, function () {
67 db.Video.load(req.params.videoId, function (err, video) { 67 db.Video.load(req.params.videoId)
68 if (err) { 68 .then(video => {
69 if (!video) return res.status(404).send('Video not found')
70
71 next()
72 })
73 .catch(err => {
69 logger.error('Error in user request validator.', { error: err }) 74 logger.error('Error in user request validator.', { error: err })
70 return res.sendStatus(500) 75 return res.sendStatus(500)
71 } 76 })
72
73 if (!video) return res.status(404).send('Video not found')
74
75 next()
76 })
77 }) 77 })
78} 78}
79 79