Reputation: 1093
I am trying to take the quantity
then add in the order
number to it then resave the value of quantity
.
// update expendable quantity POST
app.post('/dashboard/it/expendable/:id',
setRedirect({auth: '/login', success: '/dashboard/it/expendable', failure: '/dashboard/it/expendable'}),
isAuthenticated,
(req, res, next) => {
Expendable.findById(req.parms.id, function(err, expendable) {
if (err) return (err);
expendable.quantity = expendable.quantity + req.body.order;
expendable.save(function(err) {
if (err) return (err);
req.flash('success', { msg: 'Expendable checked out.' });
res.redirect(req.redirect.success);
});
});
next();
});
It currently just adds the req.body.order
onto the end of the expendable.quantity
instead of adding it to it numerically.
I don't see why it is not working, I have similar code using -
and it works but but +
doesn't. I did look on google to see and everything I found showed just to use var1 + var2
.
I did check datatype and it is number and the input is a number type as well.
Upvotes: 2
Views: 431
Reputation: 1099
I would parse them into numbers, it's most likely that one of them is a string and in that case, it appends: "5" + 5 = "55"
, "5" - 5 = 0
Upvotes: 3