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

added new functionality #10

Open
wants to merge 1 commit 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 app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const app = express();
var mongoose = require('mongoose');
mongoose.connect(process.env.DATABASE, {
useNewUrlParser: true,
useUnifiedTopology: true
useUnifiedTopology: true,
useFindAndModify: false
});

mongoose.connection
Expand Down
10 changes: 4 additions & 6 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ router.post('/',[
function updateUser(req, res){
const errors = validationResult(req);
if(errors.isEmpty()){
User.findOneAndUpdate({_id: req.body._id}, req.body, {new: true}, (err, user) => {
if(!err) {
req.redirect('/users');
} else{
console.log(err);

User.findOneAndUpdate({_id: req.body._id}, {$set:req.body}, {new: true}, (err, doc) => {
if (err) {
console.log("Updating data failed!");
}
res.redirect('/users');
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ block content
ul
for error in errors
li= error.msg
form(class="form-registration", action = ".", method = "POST" autocomplete="false")
form(class="form-registration", action = "/", method = "POST" autocomplete="false")
input(type="hidden", name="_id" value=data._id)
- var h1Classes = ['h3', 'mb-3', 'font-weight-normal']
h1(class=h1Classes) Enter User Details to be Add
Expand Down