Back End Development and APIs Projects - Exercise Tracker

Tell us what’s happening:
Can’t pass test 8 - The response returned from POST /api/users/:_id/exercises will be the user object with the exercise fields added.. I’ve compared my response JSON structure with the example and it looks the same, but the test doesn’t passes.

const personSchema = mongoose.Schema({
  username: { type: String, required: true, unique: true },
});

const exerciseSchema = mongoose.Schema({
  user_id: { type: String, required: true },
  description: { type: String, required: true },
  duration: { type: Number, required: true },
  date: { type: String },
})

let User = mongoose.model('User', personSchema);
let Exercise = mongoose.model('Exercise', exerciseSchema);

app.post('/api/users/:_id/exercises', (req, res) => {
  connect();
  const body = req.body;
  const date = checkDate(req.params.date);
  User.findById(req.params._id).exec((err, user) => {
    Exercise.create({ user_id: user._id, description: body.description, duration: body.duration, date: date }, (err, data) => {
      err ? console.error(err) : res.json({
        "_id": user._id,
        "username": user.username,
        "date": data.date,
        "duration": data.duration,
        "description": data.description,
      });
    });
  });
});

Your project link(s)

solution: boilerplate-project-exercisetracker - Replit

githubLink: GitHub - EllyanF/boilerplate-project-exercisetracker: A boilerplate for a freeCodeCamp project.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

@EllyanF I just tested you app out. If I submit and exercise with a different date than today, it still returns an object with today’s date.

The following line is the problem:

const date = checkDate(req.params.date);

And it has nothing to do with the checkDate function.

Yeah, i was getting the params date, not the body one, also my checkDate function wasn’t working properly, fixed them and all tests passed. Thank you.

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