Tell us what’s happening:
Im trying to finish the challenge but unable to pass two test:
Test 8: Failed:The response returned from POST /api/users/:_id/exercises
will be the user object with the exercise fields added.
Test 15: Failed: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.
Your code so far
const response = {
_id: user._id,
username: user.username,
description: newExercise.description,
duration: newExercise.duration,
date: new Date(newExercise.date).toDateString(),
};
console.log(response);
res.json(response);
// Extract logs from the user and format the date
logs = logs.map((log) => ({
description: log.description,
duration: log.duration,
date: new Date(log.date).toDateString(), // Convert date to a readable format
}));
// Construct the response object
const userLog = { _id: userId, username: user.username, count, log: logs };
// Return the user object with the log array and a count of the total exercises.
return res.json(userLog);
As shown in the image uploaded, all other tests are passing successfully. Have tried many ways and data output is fine; don’t know which solution the test is asking.
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Challenge Information:
Back End Development and APIs Projects - Exercise Tracker