Tell us what’s happening:
I am having problem with adding exercise but the my printing all log test is ok and next one print selected log have also the problem
Your code so far
app.post('/api/exercise/add', function(req,res){
const { userId, description, duration, date} = req.body;
const dateObj = date === '' ? new Date() : new Date(date);
if(!getUserNameById(userId)){
return res.json("User Not found");
}
const newExercise= {
_id : userId,
username: getUserNameById(userId),
date: dateObj.toString(),
duration: +duration,
description
}
exercise.push(newExercise);
res.json(newExercise);
});
app.get('/api/exercise/log',function(req,res){
const { userId, from, to, limit } = req.query;
const exe = getex(userId);
let log = getex(userId);
if(from){
const fromDate = new Date(from);
log = log.filter(exe => new Date(exe.date) > fromDate);
}
if(to){
const fromDate = new Date(from);
log = log.filter(exe => new Date(exe.date) < fromDate);
}
if(limit){
log = log.slice(0, +limit)
}
res.json({
_id:userId,
username: getUserNameById(userId),
count:log.length,
log
})
})
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
.
Challenge: Exercise Tracker
Link to the challenge: