Hi guys !
whats wrong ? no pass the test
app.post('/api/users/:_id/exercises',(req,res)=>{
(async ()=> {
const user_id = req.params._id;
let userExercise = {};
let date = new Date(Date.now()).toDateString();
try {
const user = await User.findById({_id:user_id})
if(user) {
if(req.body.date) {
date = new Date(req.body.date).toDateString();
}
const exercise = new Exercise({username:user.username,
description:req.body.description,
duration:req.body.duration,
date:date,
userId:user._id
});
const newExercise = await exercise.save();
userExercise = {
_id:user._id,
username:user.username,
date:newExercise.date,
duration:newExercise.duration,
description:newExercise.description
}
res.json(userExercise);
}else {
res.json({error:'_id dont exist'});
}
}catch(err) {
res.json({error:err});
};
})();
}) //app.post :_id/exercises
Best regard