can someone help me with NodeJS problem. When the button is clicked i want to send PUT request and update breakfast input. Problem is, this is what i have: ```
//Update
router.put("/:id", middleware.checkOwnership, function(req,res){
if(req.body.person.breakfast == "") {
req.body.person.lunch = req.body.person.lunch;
req.body.person.dinner = req.body.person.dinner;
} else {
req.body.person.lunch = parseInt(req.body.person.lunch) + parseInt(req.body.person.breakfast);
req.body.person.dinner = parseInt(req.body.person.dinner) + parseInt(req.body.person.lunch);
}
person.findByIdAndUpdate(req.params.id, req.body.person, function(err, updatedPerson) {
if(err) {
res.redirect("/food");
req.flash("error", "Something went wrong." )
} else {
res.redirect("/food/" + req.params.id);
}
});
});
``` Put request already exists. It just says, if breakfast is not said, leave lunch and dinner to be as it is, if breakfast is stated however, breakfast time will be added on top of lunch and dinner number.
What i want is when my button is pressed: ```
<form class="pull-right" action="/food/<%=person.id%>" method="post">
<button class="btn btn-info" name="goodmorning" value="Good Morning">Good Morning</button>
</form>
``` All it should do is set person.breakfast to be = Date.now hours.. Not sure what i gotta do.
via The Garrus
No comments:
Post a Comment