1 import { body } from 'express-validator/check'
2 import * as express from 'express'
4 import { database as db } from '../../../initializers'
5 import { isHostValid, logger } from '../../../helpers'
6 import { checkErrors } from '../utils'
8 const remotePodsAddValidator = [
9 body('host').custom(isHostValid).withMessage('Should have a host'),
10 body('email').isEmail().withMessage('Should have an email'),
11 body('publicKey').not().isEmpty().withMessage('Should have a public key'),
13 (req: express.Request, res: express.Response, next: express.NextFunction) => {
14 logger.debug('Checking podsAdd parameters', { parameters: req.body })
16 checkErrors(req, res, () => {
17 db.Pod.loadByHost(req.body.host)
19 // Pod with this host already exists
21 return res.sendStatus(409)
27 logger.error('Cannot load pod by host.', err)
34 // ---------------------------------------------------------------------------
37 remotePodsAddValidator