Back End Development and APIs Projects - Exercise Tracker

Hello I’ve everyone, I’m having some trouble passing the 7th test of the Exercise tracker project. My response seems correct to me and I’ve tried every solution on every similar issue posted I could find; still doesn’t work.
Your help will be appreciated.

The test : You can POST to /api/users/:_id/exercises with form data description , duration , and optionally date . If no date is supplied, the current date will be used.

app.post("/api/users/:_id/exercises", async (req, res) => {
  try {
 
    if (!req.body.description || !req.body.duration) {
      throw new Error("Error");
    }
    if (!req.params._id) {
      return res.json({
        error: "ID not found",
      });
    }

    let user = await User.findOne({ _id: req.params._id });
    if (!user) {
      return res.json({
        error: "ID not found",
      });
    }
    let log = new Log({
      description: req.body.description,
      duration: Number(req.body.duration),
      date:
        req.body.date === "" || !req.body.date
          ? new Date()
          : new Date(req.body.date),
      user: user._id,
    });
    await log.save();

    return res.json({
      _id: user._id,
      username: user.username,
      date: !req.body.date
        ? moment().format("ddd MMM DD YYYY")
        : moment(log.date).format("ddd MMM DD YYYY"),
      duration: Number(log.duration),
      description: log.description,
    });
  } catch (e) {
    console.log(e);
    return res.json({ error: e.message });
  }
});

Your project link(s)

solution: https://boilerplate-project-exercisetracker.espiramos.repl.co

githubLink: GitHub - espiramos/exercise-tracker-freecodecamp

Your browser information:

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

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

The test is broken. It has been fixed but is not in production yet.
https://forum.freecodecamp.org/t/i-cant-find-the-solution-for-exercise-tracker/561434/8

Oh thanks. Any info on when it will be in production?

2 Likes

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