Tell us what’s happening:
I’m struggling with the last two tests. For whatever reason, it doesn’t seem to be accepting the format of the date despite it being seemingly exactly what they asked for.
The
date
property of any object in thelog
array that is returned fromGET /api/users/:id/logs
should be a string… Use thedateString
format of theDate
API.
My response:
{
username: 'fcc_test_16358184666',
count: 2,
_id: '61809be274adb8d8bcea3699',
log: [ { description: 'test', duration: 60, date: 'Mon Jan 01 1990' } ]
}
As for the very last challenge, I tried the following:
app.get("/api/users/:_id/logs", async (req, res) => {
const userId = req.params._id;
const documentLimit = Number(req.query.limit) || 0;
const from = req.query.from || new Date(0);
const to = req.query.to || new Date(Date.now());
const userDocument = await User.findById(userId);
const logDocument = await Log.find({
username: userDocument.username,
log: {
$elemMatch: {
date: {
$gte: from,
$lte: to
}
}
}
});
const logResponse = {
username: userDocument.username,
count: logDocument.count,
_id: userId,
log: logDocument.log.slice(0, documentLimit + 1)
};
res.json(logResponse);
});
But logDocument
returns nothing, or undefined. Any help would be greatly appreciated!
Your project link(s)
solution: boilerplate-project-exercisetracker - Replit
Your browser information:
User Agent is: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:93.0) Gecko/20100101 Firefox/93.0
Challenge: Exercise Tracker
Link to the challenge: