I am facing issue with pass from , to and limit parameters to a GET /api/users/:_id/logs
on browser working all good pls help me, stuck from 5 days
//list log
app.get(’/api/users/:_id/logs’, (req, res,done) => {
const {_id} = req.params;
let {from, to, limit}= req.query;
Exercise.findById(_id, (err, exercise) => {
if (err) return console.log(err);
exercise.log.map(a=>a.duration=parseInt(a.duration));
if(typeof from !== ‘undefined’ && typeof to !== ‘undefined’){
var from_dt = new Date(from);
var to_dt = new Date(to);
exercise.log = exercise.log.filter(a => {
var date = new Date(a.date);
return (date >= from_dt && date <= to_dt);
});
}
if (limit){exercise.log=exercise.log.slice(0,limit)}
res.json({
_id: _id,
username: exercise.username,
count: exercise.log.length,
log: exercise.log
});
done(null, exercise);
});
});
Your project link(s)
solution: boilerplate-project-exercisetracker - Replit
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36
Challenge: Exercise Tracker
Link to the challenge: