From 8a02bd0433b7101c5ea36e87a4edb63204d2adec Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 19 Oct 2017 09:43:01 +0200 Subject: Add pod list endpoint with pagination, sort... --- server/middlewares/validators/remote/pods.ts | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 server/middlewares/validators/remote/pods.ts (limited to 'server/middlewares/validators/remote/pods.ts') diff --git a/server/middlewares/validators/remote/pods.ts b/server/middlewares/validators/remote/pods.ts new file mode 100644 index 000000000..f917b61ee --- /dev/null +++ b/server/middlewares/validators/remote/pods.ts @@ -0,0 +1,38 @@ +import { body } from 'express-validator/check' +import * as express from 'express' + +import { database as db } from '../../../initializers' +import { isHostValid, logger } from '../../../helpers' +import { checkErrors } from '../utils' + +const remotePodsAddValidator = [ + body('host').custom(isHostValid).withMessage('Should have a host'), + body('email').isEmail().withMessage('Should have an email'), + body('publicKey').not().isEmpty().withMessage('Should have a public key'), + + (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking podsAdd parameters', { parameters: req.body }) + + 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) + }) + }) + } +] + +// --------------------------------------------------------------------------- + +export { + remotePodsAddValidator +} -- cgit v1.2.3