Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation #57

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
14 changes: 13 additions & 1 deletion src/router.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const dbQueries = require('./db_queries.js');
const joi = require('joi');

const staticFiles = {
method: 'GET',
Expand Down Expand Up @@ -35,6 +36,7 @@ const add = {
}
}

// payload.dish, payload.description, payload.chef_name, payload.background_color
const createPost = {
method: 'post',
path: '/create-post',
Expand All @@ -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()
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion views/add.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form method="post" action="/create-post">
<form name="myForm" method="post" action="/create-post">
<label for="dish">Dish: </label>
<input type="text" name="dish" required/>

Expand Down