Can’t Pass The 8th test :
the Problem:
although i see the response is identical to what freecodecamp implementation provide, i can’t pass the test !!
which is overwhelming
thank you for your time in advance
the test is :
Failed: The response returned from POST /api/users/:_id/exercises
will be the user object with the exercise fields added.
the responsable code:
app.post('/api/users/:_id/exercises', (req, res) => {
var id = req.params._id;
var desc = req.body.description;
var dur = Number(req.body.duration);
var date = req.body.date == '' ? new Date(Date.now()) : new Date(req.body.date)
Exercise.create({
'date': date.toDateString(),
'duration': dur,
'description': desc
})
.then( async (exer) => {
var ExId = exer._id;
usr = await User.findById(id).exec();
usr.logs.push(exer._id);
usr.save()
.then(async (usr) => {
usr = await usr.populate({
path: 'logs',
match: {_id: ExId}
})
usr = usr.toObject({versionKey: false});
result = {...usr, ...usr.logs[0]}
delete result.logs
res.json(result);
});
})
.catch((err) => {
if (err) throw err
});
});
response Screenshots:
FreeCodeCamp solution:
you can find it in the challenge page down
Your project link(s)
solution: boilerplate-project-exercisetracker - Replit
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0
Challenge: Back End Development and APIs Projects - Exercise Tracker
Link to the challenge: