Exercise Tracker - POST /api/users/:_id/exercises

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

Can you provide more information? The more you say, the more people will be able to help.

thanks !

My code working good via postman tools too via replit platform but not here to frrecodecamp?

maybe this help

best

more information!

Please don’t wrap plaintext in code formatting. It makes your text harder to read and interferes with automatic translation tools.

I guess tha Date param has some problem

Your app is listening on port 3000
62a2837dfe709ad8b7e739f7
test
60
1990-01-01
62a2837dfe709ad8b7e739fc
test
60
1990-01-01
62a2837efe709ad8b7e73a01
test
60
undefined
62a2837efe709ad8b7e73a08
test
60
undefined
62a2837ffe709ad8b7e73a0f
test
60
undefined
62a2837ffe709ad8b7e73a16
test
60
undefined
62a2837ffe709ad8b7e73a1d
test
60
undefined
62a28380fe709ad8b7e73a24
test
60
undefined
62a28380fe709ad8b7e73a2b
test
60
undefined
62a28381fe709ad8b7e73a32
test
60
1990-01-01
62a28381fe709ad8b7e73a32
test

ok what I must be do?

Resolved!

the example print out :

{"_id":"6294a5f48413530938cc3ede","username":"mario.reiley","date":"Mon May 30 2022","duration":2,"description":"ssss"}

but don’t work!

my original print out was:

        userExercise = {
          _id:user._id,
          username:user.username,
          date:newExercise.date,
          duration:newExercise.duration,
          description:newExercise.description
        }

for pass the test is :

        userExercise = {
          username:user.username,
          description:newExercise.description,
          duration:newExercise.duration,  
          _id:user._id,
          date:newExercise.date.toDateString().substring(0,15)
        }

best