diff --git a/package.json b/package.json index 31ff649..dcee8c0 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,11 @@ "main": "index.js", "dependencies": { "env2": "^2.1.1", - "pg": "^6.1.5", "handlebars": "^4.0.6", "hapi": "^16.1.1", "inert": "^4.2.0", + "joi": "^10.4.1", + "pg": "^6.1.5", "vision": "^4.1.1" }, "devDependencies": { diff --git a/src/router.js b/src/router.js index 87bd623..b79df2d 100644 --- a/src/router.js +++ b/src/router.js @@ -1,5 +1,6 @@ const path = require('path'); const dbQueries = require('./db_queries.js'); +const joi = require('joi'); const staticFiles = { method: 'GET', @@ -35,6 +36,7 @@ const add = { } } +// payload.dish, payload.description, payload.chef_name, payload.background_color const createPost = { method: 'post', path: '/create-post', @@ -44,8 +46,18 @@ const createPost = { if(err) { return reply(err); } - reply('You added a new post'); + reply.redirect('/'); }); + }, + config: { + validate: { + payload: { + dish: joi.string().alphanum().required(), + description: joi.string().alphanum().required(), + chef_name: joi.string().alphanum().required(), + background_color: joi.string() + } + } } } diff --git a/views/add.hbs b/views/add.hbs index 4a7b34b..5c7d64d 100644 --- a/views/add.hbs +++ b/views/add.hbs @@ -1,4 +1,4 @@ -