-function podRemoveValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
- req.checkParams('id', 'Should have a valid id').notEmpty().isNumeric()
-
- logger.debug('Checking podRemoveValidator parameters', { parameters: req.params })
-
- checkErrors(req, res, function () {
- db.Pod.load(req.params.id)
- .then(pod => {
- if (!pod) {
- logger.error('Cannot find pod %d.', req.params.id)
- return res.sendStatus(404)
- }
-
- res.locals.pod = pod
- return next()
- })
- .catch(err => {
- logger.error('Cannot load pod %d.', req.params.id, err)
- res.sendStatus(500)
- })
- })
-}
+ checkErrors(req, res, () => {
+ db.Pod.loadByHost(req.body.host)
+ .then(pod => {
+ // Pod with this host already exists
+ if (pod) {
+ return res.sendStatus(409)
+ }
+
+ return next()
+ })
+ .catch(err => {
+ logger.error('Cannot load pod by host.', err)
+ res.sendStatus(500)
+ })
+ })
+ }
+]
+
+const podRemoveValidator = [
+ param('id').isNumeric().not().isEmpty().withMessage('Should have a valid id'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking podRemoveValidator parameters', { parameters: req.params })
+
+ checkErrors(req, res, () => {
+ db.Pod.load(req.params.id)
+ .then(pod => {
+ if (!pod) {
+ logger.error('Cannot find pod %d.', req.params.id)
+ return res.sendStatus(404)
+ }
+
+ res.locals.pod = pod
+ return next()
+ })
+ .catch(err => {
+ logger.error('Cannot load pod %d.', req.params.id, err)
+ res.sendStatus(500)
+ })
+ })
+ }
+]