Exercise tracker that i created in heroku can not pass the test

I am stacked on ** You can make a GET request to /api/users/:_id/logs to retrieve a full exercise log of any user.** when i test the logs, it returns me all the users, but cant pass the tests. here i share my app link.exercise-tracker it is working well.But i didnt understand why cant pass. Also i want to share my code that returns the logs

app.get('/api/users/:_id/logs', (req, res) => {
  const id = req.params._id;
  User.findById(id, (err, data) => {
    if (err) return console.log(err);
    res.json({
      _id: id,
      username: data.username,
      count: data.__v,
      log: data.log.map((e) => {
        return {
          description: e.description,
          duration: e.duration,
          date: new Date(e.date).toDateString(),
        };
      }),
    });
  });
});

also this is how i add new exercises

app.post('/api/users/:id/exercises', (req, res) => {
  const id = req.params.id;
  const description = req.body.description;
  const duration = req.body.duration;
  const date = req.body.date;
  console.log(duration);
  console.log(id);
  User.findById(id, (err, user) => {
    console.log(user);
    if (err) return console.log(err);
    // user.count = user.count + 1;
    user.log.push({
      description: description,
      duration: duration,
      date: new Date(date).toDateString(),
    });
    user.save((err, data) => {
      if (err) return console.log(err);
      res.json({
        _id: id,
        username: data.username,
        date: new Date(date).toDateString(),
        duration: JSON.parse(duration),
        description: description,
      });
    });
  });
});

also github link related [github link]
(https://github.com/sayinmehmet47/boilerplate-project-exercisetracker)

also this is how i add the execises to mongodb

It looks like functionality of adding exercises is not working in your app. Test users have empty arrays with exercises. I wasn’t able to add new exercise - app crashed.

Hey,

when i run FCC tests i see multiple has been blocked by CORS policy, can it be the issue?
upd:

so maybe i forget to give permission on mongodb. But half of the test is passing.

I have to look at the CORS policy, because in my computer it is not firing this error. Or maybe heroku restrict the other users?

can anybody why this error occur? Access to fetch at ‘https://exercise-tracker12.herokuapp.com/api/users/6139de38b67e6c43728ba1eb/exercises’ from origin ‘https://www.freecodecamp.org’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled. but i couldnt find the fix to solve no-cors issue

Hello there,

That error would show up for one route, if your app is not responding correctly - the route has something wrong with it’s logic, and is hanging.

Have your debugged what data you are getting here?:

user.save((err, data) => {

Hope this helps

i think the users are saving without problem from my computer. and turn the logs well.look



i couldnt find any bug in post to app.post(‘/api/users/:id/exercises’, (req, res)

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