Back End Development and APIs Projects - Exercise Tracker

Tell us what’s happening:
Describe your issue in detail here.
Not able to pass the final test wiped cluster and data base but still cannot pass
i have listed my code here
and i believe my data comparison is wrong please help been stuck with this for days now!!!
app.get(‘/api/users/:_id/logs’, (req, res) => {
const { from, to, limit } = req.query;
let idJson = { “id”: req.params._id };
let idToCheck = idJson.id;

// Check ID
UserInfo.findById(idToCheck, (err, data) => {
var query = {
username: data.username
}

if (from !== undefined && to === undefined) {
  query.date = { $gte: new Date(from)}
} else if (from === undefined && to !== undefined) {
  query.date = { $lte: new Date(to) }
} else if (from !== undefined && to !== undefined) {
  query.date = { $gte: new Date(from), $lte: new Date(to)}
}

let limitChecker = (limit) => {
  let maxLimit = 10;
  if (limit) {
    return limit;
  } else {
    return maxLimit
  }
}

if (err) {
  console.log("error with ID=> ", err)
} else {

  ExerciseInfo.find((query), null, {limit: limitChecker(+limit)}, (err, docs) => {
    let loggedArray = [];
    if (err) {
      console.log("error with query=> ", err);
    } else {

      let documents = docs;
      let loggedArray = documents.map((item) => {
        return {
          "description": item.description,
          "duration": item.duration,
          "date": item.date.toDateString()
        }
      })

      const test = new LogInfo({
        "username": data.username,
        "count": loggedArray.length,
        "log": loggedArray,
      })

      test.save((err, data) => {
        if (err) {
          console.log("error saving exercise=> ", err)
        } else {
          console.log("saved exercise successfully");
          res.json({
            "_id": idToCheck,
            "username": data.username,
            "count": data.count,
            "log": loggedArray
          })
        }
      })
    }
  })
}

})
})

Your project link(s)

solution: boilerplate-project-exercisetracker-3 - Nix (beta) Repl - Replit

Your browser information:

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

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

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