Reputation: 57
let carRentalInfo = require('../models/carRental-model.js');
var infocar = {
userName: req.body.userName,
password: req.body.password,
email:req.body.email,
firstName:req.body.firstName,
lastName:req.body.lastName
};
exports.findOne = (req, res) => {
carRentalInfo.findById(req.params)
.then(infocar => {
console.log("yelo!!!",infocar)
if(!infocar) {
console.log("yelo!!!",infocar)
return res.status(404).send({
message: "customer's information not found for Customer's id " + req.params.carRentalId
});
}
res.send(infocar);
}).catch(err => {
if(err.kind === 'ObjectId') {
return res.status(404).send({
message: "Customer's information not found with Customer's id " + req.params.carRentalId
});
}
return res.status(500).send({
message: "Error retrieving Customer's information with customer's id " + req.params.carRentalId
});
});
};
Always getting 404 error with the message Customer's information not found with Customer's id even after passing carRentalId as parameter. I was trying to populate customer's information based on carRentalId
Upvotes: 0
Views: 173
Reputation: 542
You need to pass id only in case if you use findById method. But you're passing all the request params. To make it work you just need to change your model call this way:
carRentalInfo.findById(req.params.id)
Upvotes: 1