I am trying to return lists of data relating to logged in users. I have created an API below to return this but I am getting an error message “Unhandled Rejection (TypeError): dispatch is not a function” error when I try to access the API in componentDidMount on the front-end.
Is req.body.username the correct way to return the correct data on the API in the back-end? Does the service method on the front-end have to send the logged in users username to the back-end when the data request is made?
const db = require("../server/models/");
const approvedDivingSchool = db.approvedDivingSchool;
exports.userDiveLog = (req, res) => {
diveLog.findAll({
where: {
[Op.and]: [
{diverUserNumber: req.body.username},
//{diveVerifiedBySchool: true}
]
},
})
.then((diveLog) => {
const userDiveLogList = [];
for (i = 0; i < diveLog.length; i++) {
userDiveLogList.push(diveLog[i].dataValues);
}
if (!diveLog) {
return res.status(404).send({ message: "No dive logs stored belonging to this individual." });
}
res.status(200).send({
data: userDiveLogList
});
})
.catch((err) => {
res.status(500).send({ message: err.message });
});
};