Back End Development and APIs Projects - Exercise Tracker

Tell us what’s happening:
Hi, I’m try to pass the tests and in 6, I think I meet the requirements but the validation is wrong.

I think it may be the data date or number. I have searched the MDN documentation and I did not find a method to take that date format.

Project links
//replit

Browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

Your POST exercise route is 404’ing everything. Open the browser console while running the tests to monitor progress.

Add some logging in that route

router.post('/users/:_id/exercises', async (req, res) => {
  try{
    //in the html file as a property of name tien [:_id], "I don't want to change the html, it may be for internal FCC balidations
      console.log(`req.body: ${JSON.stringify(req.body)}`);
console.log(`req.params: ${JSON.stringify(req.params)}`);
console.log(`req.query: ${JSON.stringify(req.query)}`);

    console.log('howdy from exercises');
    const _id = req.body[':_id']
    const { description, duration } = req.body;
    let date = req.body['date']
    // if lenght too?
    if(ObjectId.isValid(_id)) console.log(`isValidObjectId -> ${ObjectId.isValid(_id)}`)
    if(!await User.findOne({ _id })) {
        console.log(`I think user ${_id} is not in the DB.`);
        return res.status(404).json({ user: 'not exist' });
    }

and look at the logging output:

req.body: {"description":"test","duration":"60","date":"1990-01-01"}
req.params: {"_id":"640fa3d79698d4cd9230799b"}
req.query: {}
howdy from exercises
I think user undefined is not in the DB.

Always log the route inputs and all route responses when debugging.

Thank you. I have done what you told me.
I have found a configuration that is simpler and more functional than my code and I decided to adapt it.

That is to say “I found”, I changed my configuration. I am trying to improve my English. I am a native Spanish.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.