Tell us what’s happening:
Describe your issue in detail here.
can’t pass Exercise Tracker, error: the date property should be a string
but actually the date property is string, I don’t know shy I just can’t pass
Your project link(s)
my code is as below:
// post api, add a new exercise record to a given user
app.post('/api/users/:_id/exercises',(req,res) => {
const {_id} = req.params;
const {description, duration} = req.body;
const date = req.body.date == ''?new Date().toDateString():new Date(req.body.date).toDateString();
let newExercise = {description,duration:parseInt(duration),date}
userExercise.findOneAndUpdate(
{_id:_id},
{ $push: {log:newExercise} },
{returnOriginal:false,useFindAndModify:false},
(err,result) => {
if(err) return console.error(err);
res.json({username:result.user,description,duration:parseInt(duration),date,_id:result._id})
}
);
})
// GET user's exercise log: GET /api/users/:_id/logs?[from][&to][&limit]
// [ ] = optional
// from, to = dates (yyyy-mm-dd); limit = number
app.get('/api/users/:_id/logs', (req,res) => {
let {_id} = req.params;
let {from,to,limit} = req.query;
userExercise.findById(_id,(err,result) => {
if(err) return console.error(err);
let filteredExercise = result.log;
if(from)
filteredExercise = filteredExercise.filter(e => new Date(e.date) > new Date(from) );
if(to)
filteredExercise = filteredExercise.filter(e => new Date(e.date) < new Date(to) );
if(parseInt(limit) > 0){
filteredExercise = filteredExercise.slice(0,parseInt(limit));
}
let logs = []
filteredExercise.forEach(item => {
const {description,duration,date} = item
logs.push({description,duration,date,})
})
res.json({username:result.user,count:filteredExercise.length,_id:result._id,log:logs});
})
})
and the response return is as below:
Could anyone help me?
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36
Challenge: Exercise Tracker
Link to the challenge: