Hello! Sorry if this topic has been repeated a lot in the past, but I’ve gotten every test case for Exercise Tracker to pass except for " You can add from
, to
and limit
parameters to a GET /api/users/:_id/logs
request to retrieve part of the log of any user. from
and to
are dates in yyyy-mm-dd
format. limit
is an integer of how many logs to send back."
Here’s the relevant code (you can ignore the console.log
s):
app.get("/api/users/:id/logs", function(req, res) {
console.log(`req.body: ${JSON.stringify(req.body)}`);
console.log(`req.params: ${JSON.stringify(req.params)}`);
console.log(`req.query: ${JSON.stringify(req.query)}`);
Exercise.findById(req.params.id).exec(function(err, exercise) {
if (req.query.from && req.query.to) {
exercise = [exercise].filter(i => Date.parse(i.date) > Date.parse(req.query.from)) && [exercise].filter(i => Date.parse(i.date) < Date.parse(req.query.to));
}
if (req.query.limit) {
exercise = [exercise].slice(0, req.query.limit);
}
if (!req.query.from && !req.query.to && !req.query.limit) {
exercise = [exercise];
}
User.findById(req.params["id"], function(err, docs) {
res.json({
username: docs.username,
count: [exercise].length,
_id: req.params["id"],
log: exercise
})
console.log({
username: docs.username,
count: [exercise].length,
_id: req.params["id"],
log: exercise
})
})
});
})
And here’s the repl: https://replit.com/@yarjuny/Exercise-Tracker-Project. Let me know if more information is needed!