I am written and code for the project and in my testing everything is working prefectly and matches the output freecodecamp smaple project
Here is the glitch link
I can get an array of all users by getting api/exercise/users with the same info as when creating a user.
I can add an exercise to any user by posting form data userId(_id), description, duration, and optionally date to /api/exercise/add. If no date supplied it will use current date. App will return the user object with the exercise fields added.
Hey @dev117uday, I had a look at your code and ran some tests. Apparently it’s all working indeed. Have you tried to post your code to FCC, and open the console on your Glitch project to see what errors or other things that might come up when FCC runs its tests against your code?
I can add an exercise to any user by posting form data userId(_id), description, duration, and optionally date to /api/exercise/add. If no date supplied it will use current date. App will return the user object with the exercise fields added.
still having problem with
thanks for the advice , i look into glitch’s console.log to find out the last one. #notgoingtosleeptoday
It could be. Looking at your code again, you aren’t using async/await appropriately. Try to remove them because the way your code is written, those statements are useless anyway.
else if (isNaN(dat)) {
console.log("date isNan");
res
.type("txt")
.send(`Cast to Date failed for value "${req.body.date}" at path "date"`);
}
This part of your code is making the field date be required, when it should NOT. The exercise says:
I can add an exercise to any user by posting form data userId(_id), description, duration, and optionally date to /api/exercise/add. If no date supplied it will use current date. Returned will be the user object with also with the exercise fields added.
In your mongoose schema, the date field type is Number. Change that field to type Date and you’ll be able to get rid of lots of ‘Number to String to Date’ confusing validations. You have to deal with the type Date for that field
Realistically, in a pseudo-code, what that requirements is asking you to do is pretty much the following:
find the user by its id //User.findOneById({ _id: req.body.id });
found something? Push a new object Exercise to the User exercise log array
Your User schema should have a field log of type array. Something like this:
/* log: [ {
description: { type: String, required: true },
duration: { type: Number, required: true },
date: Date
} ]
*/