Tell us what’s happening:
I have looked at the hint post and ensured that my tracker returns the correct json format when a user enters a new exercise, but the test is not passing. Can anyone help me figure out whats wrong? I know the last 3 tests aren’t workign properly, because I have yet to write that part of the program. I am only concerned with the 4th one.
Your code so far
Repl: is here!
app.post('/api/exercise/add',async (req,res)=>{
//create/save new record for exercise (needs to be different than the other one)
//can this return the object? if so, save it to a variable and return it with res.json below!
let tempDate = undefined
if (req.body.date){
tempDate = new Date(req.body.date)
}else{
tempDate = new Date()
}
createAndSaveExercise(req.body.userId, req.body.description, req.body.duration, tempDate)
let theUser = await User.findById(req.body.userId).exec()/*, function(err, user){
if(err){
console.error('user not found')
return res.json({"error": "user not found"})
}else{
return user
}
})*/
console.log(theUser)
let user_object= theUser
res.json({username: user_object.username, description: req.body.description, duration: req.body.duration,_id: req.body.userId, date: tempDate.toDateString()})
})
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
.
Challenge: Exercise Tracker
Link to the challenge: