Please help me with my code. I can run it in my repl and browser but when I put this solution to FCC page, it didn’t pass from test 9 until the end. Seems its can’t accept my code for log router
app.get('/api/users/:_id/logs', async (req, res) => {
let { from, to, limit } = req.query;
const userId = req.params._id;
const searchLog = await Exercise.findById(userId);
if (!searchLog) {
res.json({ error: 'There are not ID like that' })
}
let filter = { userId };
let dateFilter = {};
if (from) {
dateFilter['$gte'] = new Date(from);
}
if (to) {
dateFilter['$lte'] = new Date(to);
}
if (from || to) {
filter.date = dateFilter;
}
if (!limit) {
limit = 100;
}
let exercises = await List.find(filter).limit(limit);
exercises = exercises.map((exercise) => {
return {
description: exercise.description,
duration: exercise.duration,
date: exercise.date.toDateString(),
};
});
res.json({
username: searchLog.username, count: exercises.length, _id: searchLog._id, log: exercises,
});
});
Please see my code, there are something I need to be fixed ?