Tell us what’s happening:
I am having issues with the last second test case 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.
I have tested my code for each type of inputs such as when no date is supplied and when a date is supplied in (yyyy-mm-dd) format. But somehow while running the freeCodeCamp’s test there seem to be some problem in the date
property there are cases where the date stored is “Invalid Date”. I can’t seem to find the workaround for this.
I am handling my date as follows:
let date_input;
if (req.body.date === "") {
date_input = new Date(Date.now());
}
else {
date_input = new Date(req.body.date);
}
The response sent is as follows:
res.json({
_id: new_exercise.user_id,
username: new_exercise.username,
description: new_exercise.description,
duration: new_exercise.duration,
date: new Date(new_exercise.date).toDateString()
});
Solution Link
https://fcc–exercise-tracker.herokuapp.com/
Your code so far
https://github.com/d02ev/freecodecamp–exercise-tracker
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0
Challenge: Back End Development and APIs Projects - Exercise Tracker
Link to the challenge: