What wrong?
my endpoint :
app.get('/api/users/:_id/logs',(req,res)=>{
(async () => {
try {
// console.log(req.params._id);
// console.log(req.query.from);
// console.log(req.query.to);
// console.log(req.query.limit);
// user data
const dataUser = await User.findById({_id:req.params._id})
if(dataUser) {
let from, to = Date.now(); let limit = 0;
if(req.query.from) {from = req.query.from;}
if(req.query.to) {to = req.query.to;}
if(req.query.limit) {limit = req.query.limit;}
// exercise data
const exerciseLog = await Exercise.find({userId:dataUser._id})
.select(['-_id','description','duration','date'])
.where('date').gte(from).lte(to)
.limit(limit)
.exec();
// {
// username: "fcc_test",
// count: 1,
// _id: "5fb5853f734231456ccb3b05",
// log: [{
// description: "test",
// duration: 60,
// date: "Mon Jan 01 1990",
// }]
// }
// const expected = {
// username,
// description: 'test',
// duration: 60,
// _id,
// date: new Date().toDateString()
// };
const userLog = {
username: dataUser.username,
count: exerciseLog.length,
_id: dataUser._id,
log: exerciseLog
};
// send res
// console.log(userLog);
res.json(userLog);
}
}catch(e){
res.json({error:e.message});
};
})(); //async
}); ///api/users/:_id/logs
the exercise object is :
{ description: 'test', duration: 60, date: 1990-01-01T00:00:00.000Z }
{ description: 'test', duration: 60, date: 1990-01-03T00:00:00.000Z }
Finally I pass the test!
I do for myself and so that others do not waste time with the traps that are here, I will make some things clearer:
1) the count property cannot be 0
2) the log array must be of type array and must contain at least one element: the description must be of type string, the duration must be a number and the date must be in the format Date().toDateString()
data should be : description:'test',duration:60, date: new Date().toDateString()}
3) the array must be called log
4) pay attention there is a bug in the index.html file right on this line
<input id="uid" type="text" name="_id" placeholder=":_id" />
the name=":_id" those points should not be there
Thank you
update your solution in github i saw im still getting error last test case
Sorry if freecodecamp platform say is good then is good!
In real programming if you are asked for A you must write A, you don't imagine anything
best regard