router.post(
'/addshipment/:user_id',
passport.authenticate('jwt', { session: false }),
(req, res) => {
Shipments.findOne({_id: req.params.user_id}, {paymentStatus: "incomplete"})
.then(shipments => {
if(!shipments){
const errwarehouse = 'This user doesn't have a warehouse, kindly create that first'
return res.status(404).json(errwarehouse);
}else{
const newPackages = {
category: req.body.category,
quantity: req.body.quantity,
description: req.body.description,
trackingno: 1234321,
length: req.body.length,
height: req.body.height,
width: req.body.width,
weight : 12
};
shipments.packages.push(newPackages);
shipments
.save()
.then(shipments => res.json(shipments))
.catch(err => console.log(err));
}
});
});
i don't know why i do get this error,
"TypeError: Cannot read property 'push' of undefined"
because all am trying to acheive is to make sure i am able post post into the package array