Failing Test 4 - APIs and Microservices Projects - Exercise Tracker

Tell us what’s happening:
Tests 1, 2, 3, 5 and 6 pass. Test 4 does not pass for some reason even though the payload is what was shown in the Hint

Your code so far
The problematic code is here:

app.post('/api/exercise/add', function(req, res, next) {
  const { userId, description, duration, date } = req.body
  User.findById(userId, (err, user) => {
    if(err) next(err)
    user.log.push({
      _id: user._id,
      description,
      duration,
      date: date ? date : new Date().toDateString()
    })
    user.save((err, data) => {
      const { _id ,username } = data
      if(err) next(err)

      
      res.json({
        username,
        description,
        _id,
        duration: Number(duration),
        date: date ? date : new Date().toDateString()
      })
    })
  })
})

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15.

Challenge: Exercise Tracker

Link to the challenge:

Link to repl:

https://repl.it/@AdrianMarcelMar/boilerplate-project-exercisetracker#server.js

Welcome, adrianmpop.

The date parameter must always be a Date String. So, even if a date is provided, it is best to create a Date object, and use toDateString() on it.

Hope this helps

Hi! Thanks so much for the tip! It turned out to be the issue…:man_facepalming:t2: