Backend - Exercise Tracker: Please Help Me Find Out What I Missed

I still could not pass the 8th and 15th specs, if anyone can kindly take a look and suggest what I’ve missed, since I have used toDateString() for the date, and the rendered JSON format post new insertion feels correct to me. The log array is sorted when necessary in every new input POST

Error message:

  • The response returned from POST /api/users/:_id/exercises will be the user object with the exercise fields added;
  • The date property of any object in the log array that is returned from GET /api/users/:id/logs should be a string… Use the dateString format of the Date API.

The dummy ID is: “61b955da1a85d36f9d319c4d”

JSON result for this link: https://boilerplate-project-exercisetracker.shugyoza.repl.co/api/users/61b955da1a85d36f9d319c4d/logs as follows: (The duration -and description- shows the sequence of my input, so it’s clear here that the sorting is working with the most recent date at the tail of the log array)

{
"_id": "61b955da1a85d36f9d319c4d",
"username": "reta",
"count": 8,
"log": [
{
"description": "exercise 4: 1989-02-23",
"duration": 4,
"date": "Thu Feb 23 1989",
"_id": "61b956fd1a85d36f9d319c62"
},
{
"description": "exercise 3: 2018-03-02",
"duration": 3,
"date": "Fri Mar 02 2018",
"_id": "61b956a91a85d36f9d319c5c"
},
{
"description": "exercise 7: 2020-11-11",
"duration": 7,
"date": "Wed Nov 11 2020",
"_id": "61b966defbfcd7c2cc828a0f"
},
{
"description": "exercise 1: 2021-10-13",
"duration": 2,
"date": "Wed Oct 13 2021",
"_id": "61b956581a85d36f9d319c54"
},
{
"description": "exercise 1: 2021-11-15",
"duration": 1,
"date": "Mon Nov 15 2021",
"_id": "61b9562a1a85d36f9d319c50"
},
{
"description": "exercise 6: 2021-12-12",
"duration": 6,
"date": "Sun Dec 12 2021",
"_id": "61b957dc1a85d36f9d319c7c"
},
{
"description": "exercise 5: 2021-12-13",
"duration": 5,
"date": "Mon Dec 13 2021",
"_id": "61b957511a85d36f9d319c6e"
},
{
"description": "exercise 8: 2021-12-14",
"duration": 8,
"date": "Wed Dec 15 2021",
"_id": "61b975f115e8b62814d8eab8"
}
],
"__v": 8
}

while with queries. (Link: https://boilerplate-project-exercisetracker.shugyoza.repl.co/api/users/61b955da1a85d36f9d319c4d/logs?from=1985-01-01&to=2021-12-01&limit=3
as follows:

{
"_id": "61b955da1a85d36f9d319c4d",
"username": "reta",
"from": "Tue Jan 01 1985",
"to": "Wed Dec 01 2021",
"count": 3,
"log": [
{
"description": "exercise 3: 2018-03-02",
"duration": 3,
"date": "Fri Mar 02 2018",
"_id": "61b956a91a85d36f9d319c5c"
},
{
"description": "exercise 1: 2021-10-13",
"duration": 2,
"date": "Wed Oct 13 2021",
"_id": "61b956581a85d36f9d319c54"
},
{
"description": "exercise 1: 2021-11-15",
"duration": 1,
"date": "Mon Nov 15 2021",
"_id": "61b9562a1a85d36f9d319c50"
}
]
}

For adding a log, the result is as follows:

{
"_id":"61b955da1a85d36f9d319c4d",
"username":"reta",
"date":"Sun Jan 05 2020",
"duration":"9",
"description":"exercise 9: 2020-01-05"
}

I have no idea what to look now. Thank you!

Your project link(s)

solution: https://replit.com/@shugyoza/boilerplate-project-exercisetracker

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36

Challenge: Exercise Tracker

Link to the challenge:

Waking up this morning, doing nothing, and I passed spec 15. One last spec to pass, the 8th:

The response returned from POST /api/users/:_id/exercises will be the user object with the exercise fields added.

Console.logging inputs and outputs on the specific route, sanitize from error message, and this is the result. I still did not see anything wrong within the debugging result.

START DEBUG
[Object: null prototype] {
  description: 'test',
  duration: '60',
  date: '1990-01-01',
  debug: 'Inside req.body at /api/users/:_id/exercises'
}
{
  _id: '61ba39dc9172791b05d97fb8',
  debug: 'Inside req.params at /api/users/:_id/exercises'
}
Inside req.query at /api/users/:_id/exercises

{
  debug: 'Inside rendered JSON at /api/users/:_id/exercises',
  _id: new ObjectId("61ba39dc9172791b05d97fb8"),
  username: 'fcc_test_16395944600',
  date: 'Mon Jan 01 1990',
  duration: '60',
  description: 'test'
}
END DEBUG



START DEBUG
[Object: null prototype] {
  description: 'test',
  duration: '60',
  date: '1990-01-01',
  debug: 'Inside req.body at /api/users/:_id/exercises'
}
{
  _id: '61ba39dc9172791b05d97fbd',
  debug: 'Inside req.params at /api/users/:_id/exercises'
}
Inside req.query at /api/users/:_id/exercises

{
  debug: 'Inside rendered JSON at /api/users/:_id/exercises',
  _id: new ObjectId("61ba39dc9172791b05d97fbd"),
  username: 'fcc_test_16395944606',
  date: 'Mon Jan 01 1990',
  duration: '60',
  description: 'test'
}
END DEBUG



START DEBUG
[Object: null prototype] {
  description: 'test',
  duration: '60',
  debug: 'Inside req.body at /api/users/:_id/exercises'
}
{
  _id: '61ba39dd9172791b05d97fc2',
  debug: 'Inside req.params at /api/users/:_id/exercises'
}
Inside req.query at /api/users/:_id/exercises

{
  debug: 'Inside rendered JSON at /api/users/:_id/exercises',
  _id: new ObjectId("61ba39dd9172791b05d97fc2"),
  username: 'fcc_test_16395944611',
  date: 'Wed Dec 15 2021',
  duration: '60',
  description: 'test'
}
END DEBUG



{}
{ _id: '61ba39dd9172791b05d97fc2', logs: 'logs' }
{}
{ _id: '61ba39dd9172791b05d97fc2', logs: 'logs' }

{
  _id: new ObjectId("61ba39dd9172791b05d97fc2"),
  username: 'fcc_test_16395944611',
  count: 1,
  log: [
    {
      description: 'test',
      duration: 60,
      date: 'Wed Dec 15 2021',
      _id: new ObjectId("61ba39dd9172791b05d97fc5")
    }
  ],
  __v: 1
}



START DEBUG
[Object: null prototype] {
  description: 'test',
  duration: '60',
  debug: 'Inside req.body at /api/users/:_id/exercises'
}
{
  _id: '61ba39de9172791b05d97fc9',
  debug: 'Inside req.params at /api/users/:_id/exercises'
}
Inside req.query at /api/users/:_id/exercises

{
  debug: 'Inside rendered JSON at /api/users/:_id/exercises',
  _id: new ObjectId("61ba39de9172791b05d97fc9"),
  username: 'fcc_test_16395944620',
  date: 'Wed Dec 15 2021',
  duration: '60',
  description: 'test'
}
END DEBUG



{}
{ _id: '61ba39de9172791b05d97fc9', logs: 'logs' }
{}
{ _id: '61ba39de9172791b05d97fc9', logs: 'logs' }

{
  _id: new ObjectId("61ba39de9172791b05d97fc9"),
  username: 'fcc_test_16395944620',
  count: 1,
  log: [
    {
      description: 'test',
      duration: 60,
      date: 'Wed Dec 15 2021',
      _id: new ObjectId("61ba39de9172791b05d97fcc")
    }
  ],
  __v: 1
}



START DEBUG
[Object: null prototype] {
  description: 'test',
  duration: '60',
  debug: 'Inside req.body at /api/users/:_id/exercises'
}
{
  _id: '61ba39df9172791b05d97fd0',
  debug: 'Inside req.params at /api/users/:_id/exercises'
}
Inside req.query at /api/users/:_id/exercises

{
  debug: 'Inside rendered JSON at /api/users/:_id/exercises',
  _id: new ObjectId("61ba39df9172791b05d97fd0"),
  username: 'fcc_test_16395944628',
  date: 'Wed Dec 15 2021',
  duration: '60',
  description: 'test'
}
END DEBUG



{}
{ _id: '61ba39df9172791b05d97fd0', logs: 'logs' }
{}
{ _id: '61ba39df9172791b05d97fd0', logs: 'logs' }

{
  _id: new ObjectId("61ba39df9172791b05d97fd0"),
  username: 'fcc_test_16395944628',
  count: 1,
  log: [
    {
      description: 'test',
      duration: 60,
      date: 'Wed Dec 15 2021',
      _id: new ObjectId("61ba39df9172791b05d97fd3")
    }
  ],
  __v: 1
}



START DEBUG
[Object: null prototype] {
  description: 'test',
  duration: '60',
  debug: 'Inside req.body at /api/users/:_id/exercises'
}
{
  _id: '61ba39df9172791b05d97fd7',
  debug: 'Inside req.params at /api/users/:_id/exercises'
}
Inside req.query at /api/users/:_id/exercises

{
  debug: 'Inside rendered JSON at /api/users/:_id/exercises',
  _id: new ObjectId("61ba39df9172791b05d97fd7"),
  username: 'fcc_test_16395944637',
  date: 'Wed Dec 15 2021',
  duration: '60',
  description: 'test'
}
END DEBUG



{}
{ _id: '61ba39df9172791b05d97fd7', logs: 'logs' }
{}
{ _id: '61ba39df9172791b05d97fd7', logs: 'logs' }

{
  _id: new ObjectId("61ba39df9172791b05d97fd7"),
  username: 'fcc_test_16395944637',
  count: 1,
  log: [
    {
      description: 'test',
      duration: 60,
      date: 'Wed Dec 15 2021',
      _id: new ObjectId("61ba39e09172791b05d97fda")
    }
  ],
  __v: 1
}



START DEBUG
[Object: null prototype] {
  description: 'test',
  duration: '60',
  debug: 'Inside req.body at /api/users/:_id/exercises'
}
{
  _id: '61ba39e09172791b05d97fde',
  debug: 'Inside req.params at /api/users/:_id/exercises'
}
Inside req.query at /api/users/:_id/exercises

{
  debug: 'Inside rendered JSON at /api/users/:_id/exercises',
  _id: new ObjectId("61ba39e09172791b05d97fde"),
  username: 'fcc_test_16395944645',
  date: 'Wed Dec 15 2021',
  duration: '60',
  description: 'test'
}
END DEBUG



{}
{ _id: '61ba39e09172791b05d97fde', logs: 'logs' }
{}
{ _id: '61ba39e09172791b05d97fde', logs: 'logs' }

{
  _id: new ObjectId("61ba39e09172791b05d97fde"),
  username: 'fcc_test_16395944645',
  count: 1,
  log: [
    {
      description: 'test',
      duration: 60,
      date: 'Wed Dec 15 2021',
      _id: new ObjectId("61ba39e19172791b05d97fe1")
    }
  ],
  __v: 1
}



START DEBUG
[Object: null prototype] {
  description: 'test',
  duration: '60',
  debug: 'Inside req.body at /api/users/:_id/exercises'
}
{
  _id: '61ba39e19172791b05d97fe5',
  debug: 'Inside req.params at /api/users/:_id/exercises'
}
Inside req.query at /api/users/:_id/exercises

{
  debug: 'Inside rendered JSON at /api/users/:_id/exercises',
  _id: new ObjectId("61ba39e19172791b05d97fe5"),
  username: 'fcc_test_16395944653',
  date: 'Wed Dec 15 2021',
  duration: '60',
  description: 'test'
}
END DEBUG



{}
{ _id: '61ba39e19172791b05d97fe5', logs: 'logs' }
{}
{ _id: '61ba39e19172791b05d97fe5', logs: 'logs' }

{
  _id: new ObjectId("61ba39e19172791b05d97fe5"),
  username: 'fcc_test_16395944653',
  count: 1,
  log: [
    {
      description: 'test',
      duration: 60,
      date: 'Wed Dec 15 2021',
      _id: new ObjectId("61ba39e19172791b05d97fe8")
    }
  ],
  __v: 1



}
START DEBUG
[Object: null prototype] {
  description: 'test',
  duration: '60',
  debug: 'Inside req.body at /api/users/:_id/exercises'
}
{
  _id: '61ba39e29172791b05d97fec',
  debug: 'Inside req.params at /api/users/:_id/exercises'
}
Inside req.query at /api/users/:_id/exercises

{
  debug: 'Inside rendered JSON at /api/users/:_id/exercises',
  _id: new ObjectId("61ba39e29172791b05d97fec"),
  username: 'fcc_test_16395944662',
  date: 'Wed Dec 15 2021',
  duration: '60',
  description: 'test'
}
END DEBUG



{}
{ _id: '61ba39e29172791b05d97fec', logs: 'logs' }
{}
{ _id: '61ba39e29172791b05d97fec', logs: 'logs' }

{
  _id: new ObjectId("61ba39e29172791b05d97fec"),
  username: 'fcc_test_16395944662',
  count: 1,
  log: [
    {
      description: 'test',
      duration: 60,
      date: 'Wed Dec 15 2021',
      _id: new ObjectId("61ba39e29172791b05d97fef")
    }
  ],
  __v: 1
}



START DEBUG
[Object: null prototype] {
  description: 'test',
  duration: '60',
  date: '1990-01-01',
  debug: 'Inside req.body at /api/users/:_id/exercises'
}
{
  _id: '61ba39e39172791b05d97ff3',
  debug: 'Inside req.params at /api/users/:_id/exercises'
}
Inside req.query at /api/users/:_id/exercises

{
  debug: 'Inside rendered JSON at /api/users/:_id/exercises',
  _id: new ObjectId("61ba39e39172791b05d97ff3"),
  username: 'fcc_test_16395944670',
  date: 'Mon Jan 01 1990',
  duration: '60',
  description: 'test'
}
END DEBUG



START DEBUG
[Object: null prototype] {
  description: 'test',
  duration: '60',
  date: '1990-01-02',
  debug: 'Inside req.body at /api/users/:_id/exercises'
}
{
  _id: '61ba39e39172791b05d97ff3',
  debug: 'Inside req.params at /api/users/:_id/exercises'
}
Inside req.query at /api/users/:_id/exercises

{
  debug: 'Inside rendered JSON at /api/users/:_id/exercises',
  _id: new ObjectId("61ba39e39172791b05d97ff3"),
  username: 'fcc_test_16395944670',
  date: 'Tue Jan 02 1990',
  duration: '60',
  description: 'test'
}
END DEBUG



{}
{ _id: '61ba39e39172791b05d97ff3', logs: 'logs' }
{ from: '1989-12-31', to: '1990-01-03' }
{ _id: '61ba39e39172791b05d97ff3', logs: 'logs' }

{
  _id: new ObjectId("61ba39e39172791b05d97ff3"),
  username: 'fcc_test_16395944670',
  from: 'Sun Dec 31 1989',
  to: 'Wed Jan 03 1990',
  count: 2,
  log: [
    {
      description: 'test',
      duration: 60,
      date: 'Mon Jan 01 1990',
      _id: new ObjectId("61ba39e39172791b05d97ff6")
    },
    {
      description: 'test',
      duration: 60,
      date: 'Tue Jan 02 1990',
      _id: new ObjectId("61ba39e39172791b05d97ffa")
    }
  ]
}
{}
{ _id: '61ba39e39172791b05d97ff3', logs: 'logs' }
{ limit: '1' }
{ _id: '61ba39e39172791b05d97ff3', logs: 'logs' }
    

The reason you passed the last one is because it was a time zone offset problem. You must have run the test during a period when your local time and UTC are the same date.
Here’s the spec for the log for the second:

{
  username: "fcc_test",
  count: 1,
  _id: "5fb5853f734231456ccb3b05",
  log: [{
    description: "test",
    duration: 60,
    date: "Mon Jan 01 1990",
  }]
}

Here’s the important part of your output:

{
  debug: 'Inside rendered JSON at /api/users/:_id/exercises',
  _id: new ObjectId("61ba7e428161587d1f11595f"),
  username: 'fcc_test_16396119704',
  date: 'Wed Dec 15 2021',
  duration: '60',
  description: 'test'
}

Pay close attention to that duration property.

Also, your code is generating a ton of unhandled promise rejection errors, presumably caused by this in you exercise POST route (and maybe others; I didn’t look):

    await Log.findById(
      id, // filter by id
      (err, data) => { // callback

Do async/await or callbacks, but don’t mix the two.

1 Like

Thank you!

  • Just by converting the duration into Number() made the app passed all specs; and
  • I cleaned up the errors by deleting the async await and chaining clone() to the end of every find() in reference to the documentation;
  • I’ll check for the 15th spec dateString tonight, and see if the error pops out (or it is actually not my problem at all?)

Thanks!