Tell us what’s happening:
Hi, I am attempting to do the exercise tracker test and my response check after adding an exercise is not passing in FCC. I have the exact same output as the one given in their app.
This is the response from my app after adding an exercise for a user.
Your project link(s)
solution: https://exercise-tracker-portfolio.herokuapp.com/
My Code:
const personSchema = new mongoose.Schema({
username: {type:String, unique: true}
});
const User = mongoose.model('User',personSchema);
const exerciseSchema = new mongoose.Schema({userId:String, description: String, duration: Number, date: Date})
const Exercise = mongoose.model('Exercise',exerciseSchema)
app.route('/api/users/:_id/exercises').post((req,res)=>{
let{userId,description,duration,date} = req.body;
date = date?date: Date.now();
User.findById(userId, (err,data)=>{
if(!data){
res.send("Unknown userId")
}
else{
const user = data.username
const newExercise = new Exercise({userId, description, duration, date})
newExercise.save((err,data)=>{
res.json({"_id":userId,
"username":user,
"date": new Date(date).toDateString(),
"duration": Number(req.body.duration),
"description":description })
})
}
});
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36
Challenge: Exercise Tracker
Link to the challenge:
Any help on this topic will be highly appreciated. My Atlas connection is working fine as the users are getting stored and the exercise is being added. Thanks in advance