Back End Development and APIs Projects - Exercise Tracker

Tell us what’s happening:
Hello everyone,

I am currently doing the Exercise Tracker Microservice project in the Backend Development & API’s certification. The app itself works fine. I have tested it multiple times to confirm, and the responses are exactly the same as the project requirements as well as the demo website.

The only issue I have is it seems all the tests related to the path api/users/:_id/logs fail despite it returning the appropriate response (format’s correct, and the exercise logs that are returned conform to the &from, &to, and &count queries. All other tests work fine. My endpoint code is below:

let initial;
let final;
let ct;
app.get('/api/users/:_id/logs', (req, res) => {
  //path looks like /logs?from=date1&to=date2&limit=number
      initial = new Date(req.query.from)
      initial = new Date('1970-01-01')
      final = new Date(
      final = new Date()
       ct = req.query.limit
        ct = 1000

  User.findById(req.params._id, (err, data) => {
    let gotUsername = data.username;
      console.log('user undefined.')
      Exercise.find({userId: req.params._id, date: {$gte: initial, $lte: final}}).limit(ct).exec ((err, output) => {
        let newOutput = => (
          description: o.description,
          duration: o.duration,
        res.send({username: gotUsername, _id: req.params._id, count: newOutput.length, log: newOutput})

No errors are generated when code runs, at least for me. Could someone else test it out to see if it works for them / spot what’s going on? My project link is below.

Thank you for your time.

Your project link(s)

solution: boilerplate-project-exercisetracker-5 - 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/ Safari/537.36

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

Debug your POST exercise route as that is where most of the problem is as the code is not correctly handling missing dates and produces

req.body: {"description":"test","duration":"60"}
req.params: {"_id":"63002cbbd62aa95a446332ea"}
req.query: {}
Invalid Date
Error: Exercise validation failed: date: Cast to date failed for value "Invalid Date" (type Date) at path "date"

when no date is supplied by the tests. Log the route inputs and outputs here and on the GET logs route for more information.

1 Like

Thank you so much!!! It helped a ton!

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