Back End Development and APIs Projects - Exercise Tracker

Tell us what’s happening:
Describe your issue in detail here.

Your project link(s)


solution: boilerplate-project-exercisetracker - Replit

Your browser information:

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

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

Please help me with my code. I can run it in my repl and browser but when I put this solution to FCC page, it didn’t pass from test 9 until the end. Seems its can’t accept my code for log router

app.get('/api/users/:_id/logs', async (req, res) => {
  let { from, to, limit } = req.query;
  const userId = req.params._id;

  const searchLog = await Exercise.findById(userId);

  if (!searchLog) {
    res.json({ error: 'There are not ID like that' })
  }

  let filter = { userId };
  let dateFilter = {};
  if (from) {
    dateFilter['$gte'] = new Date(from);
  }
  if (to) {
    dateFilter['$lte'] = new Date(to);
  }
  if (from || to) {
    filter.date = dateFilter;
  }

  if (!limit) {
    limit = 100;
  }

  let exercises = await List.find(filter).limit(limit);
  exercises = exercises.map((exercise) => {
    return {
      description: exercise.description,
      duration: exercise.duration,
      date: exercise.date.toDateString(),
    };
  });

  res.json({
    username: searchLog.username, count: exercises.length, _id: searchLog._id, log: exercises,
  });

});

Please see my code, there are something I need to be fixed ? :pray: :pray: :pray:

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