Added schma to validate

This commit is contained in:
Nicolai Ort 2021-08-12 19:39:10 +02:00
parent bb09b731aa
commit cfc49f3ec4
Signed by: niggl
GPG Key ID: 13AFA55AF62F269F

View File

@ -31,10 +31,20 @@ fastify.get('/:id', async (req, res) => {
}) })
//Create new urls //Create new urls
fastify.post('/new', async (req, res) => { const newUrlSchema = {
body: {
type: 'object',
properties: {
target: { type: 'string' },
shortcode: { type: 'string' },
}
}
};
fastify.post('/new', { newUrlSchema }, async (req, res) => {
const target = req.body?.target; const target = req.body?.target;
let shortcode = req.body?.shortcode; let shortcode = req.body?.shortcode;
if (!req.body?.target) { if (!target) {
res.statusCode = 400; res.statusCode = 400;
return "Missing target"; return "Missing target";
} }