I cannot get my exercise tracker app to pass test 4:
My response looks exactly like the example response and seems to fit the criteria of the test, but it will not pass.
Code:
app.post("/api/exercise/add", (req, res) => {
let newDate = 0;
if (req.body.date == "") {
newDate = new Date().toLocaleDateString(undefined, {
weekday: "short",
month: "short",
day: "numeric",
year: "numeric"
});
} else {
newDate = new Date(req.body.date).toLocaleDateString(undefined, {
weekday: "short",
month: "short",
day: "numeric",
year: "numeric"
});
}
User.findOneAndUpdate(
{ _id: req.body.userId },
{
$push: {
log: {
date: newDate.replace(/,/g, ''),
duration: parseInt(req.body.duration),
description: req.body.description
}
}
},
{ new: true, upsert: true },
(err, user) => {
res.send({_id: user._id, username: user.username, ...user.log[user.log.length - 1]});
}
);
});
Output Json:
{"_id":“606219cf581fbe3de1a0626e”,“username”:“snag”,“date”:“Sat Jun 11 1977”,“duration”:20,“description”:“Running”}
Is there a different format for the object keys that it is looking for? Is there somewhere that I can find more detailed descriptions of the test criteria than what is provided?
Project link: link
My code: GitHub repo