-
Notifications
You must be signed in to change notification settings - Fork 5
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
Added Feedback system to the Blog #18
base: master
Are you sure you want to change the base?
Changes from all commits
aeb79d4
465bc9b
5340129
c00dd83
35065ef
91cb676
3c79014
ea949fa
5a68bc9
6231396
aa3937f
e7beae1
df3778e
eee2e16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
{ | ||
"name": "csechack", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"serve": "nodemon server.js", | ||
"start": "node server.js" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"async": "^2.6.1", | ||
"ejs": "^2.6.1", | ||
"express": "^4.16.4", | ||
"mongoose": "^5.7.5", | ||
"nodemon": "^1.18.9" | ||
} | ||
"name": "csechack", | ||
"version": "1.0.0", | ||
"description": "**ABOUT** our blog-'iBlog'", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"serve": "nodemon server.js", | ||
"start": "node server.js" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"async": "^2.6.1", | ||
"ejs": "^2.6.1", | ||
"express": "^4.16.4", | ||
"express-validator": "^6.6.1", | ||
"mongoose": "^5.7.5", | ||
"nodemon": "^1.18.9" | ||
}, | ||
"devDependencies": {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
var express = require("express"); | ||
var router = express.Router(); | ||
var bodyParser = require("body-parser"); | ||
const { body, validationResult } = require('express-validator'); | ||
|
||
var mongoose = require("mongoose"); | ||
var async = require("async"); | ||
|
||
|
@@ -10,6 +12,7 @@ var Blog = require("../models/blog"); | |
router.use(bodyParser.urlencoded({ extended: false })); | ||
router.use(bodyParser.json()); | ||
|
||
|
||
router.get("/", function (req, res) { | ||
res.render("index"); | ||
}); | ||
|
@@ -42,8 +45,31 @@ router.get("/viewAllBlogs", function (req, res) { | |
}); | ||
}); | ||
|
||
router.post("/post", function (req, res) { | ||
var reqBlog = req.body.blog; | ||
router.post("/post",[ | ||
|
||
body('blog.name') | ||
.trim().not().isEmpty(), | ||
body('nodes.*.content') | ||
.trim().not().isEmpty() | ||
|
||
|
||
], function (req, res) { | ||
|
||
const errors=validationResult(req); | ||
console.log(errors); | ||
if (!errors.isEmpty()) { | ||
|
||
res.send(500); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Errors are sent with a message in this format:
|
||
console.log(errors); | ||
// console.log(req.body.nodes[0].content); | ||
|
||
} | ||
else{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use try and catch blocks for error handling btw. This helps in sending error responses for all sorts of errors, instead of sending individual response for particular errors. |
||
|
||
|
||
|
||
var reqBlog = req.body.blog; | ||
|
||
var nodes = []; | ||
var newBlog = new Blog({ | ||
name: reqBlog.name, | ||
|
@@ -81,6 +107,8 @@ router.post("/post", function (req, res) { | |
res.send(200); | ||
}) | ||
.catch((err) => {}); | ||
} | ||
|
||
}); | ||
|
||
router.post("/edit/:id", function (req, res) { | ||
|
@@ -105,6 +133,17 @@ router.post("/edit/:id", function (req, res) { | |
}); | ||
}); | ||
|
||
|
||
router.get("/posterror", function (req, res) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't write a separate route just for errors. Errors should be written for each individual route. |
||
res.send('<h1>Error:Invalid Data Sent</h1>'); | ||
}); | ||
|
||
router.get("/postStory", function (req, res) { | ||
res.render("postStory"); | ||
}); | ||
|
||
|
||
|
||
router.get("/edit/:id", function (req, res) { | ||
var nodesArr = []; | ||
// console.log(req.params.id); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can write a simple console.log here cause otherwise there's no purpose of an error handling function.