Thank you for replying.
I’m not sure what you mean by conditionals.
I don’t get the same results as you.
What does missed me
mean?
I tried logging as you suggested:
immediately after app.post('/api/users/:_id/exercises', async function(req, res) {
I put
console.log(`req.body: ${JSON.stringify(req.body)}`);
console.log(`req.params: ${JSON.stringify(req.params)}`);
console.log(`req.query: ${JSON.stringify(req.query)}`);
and these are the results:
req.body: {":_id":"6345930745dc28528ae508f7","description":"Press-ups","duration":"40","date":"2022-10-09"}
req.params: {"_id":"6345930745dc28528ae508f7"}
req.query: {}
Immediately after creating newExercise
I put
console.log(JSON.stringify(newExercise));
This is the result:
{"userid":"6345930745dc28528ae508f7","description":"Press-ups","duration":40,"date":"2022-10-09","_id":"6345f5f457dd9608dee16431"}
Immediately after const error = newExercise.validateSync();
which is the only place that error
is used, I put
console.log(JSON.stringify(error));
And this is the result:
undefined
Immediately before newExercise.save(function(err, data) {
I put
console.log(JSON.stringify(newExercise));
This is the result
{"userid":"6345930745dc28528ae508f7","description":"Press-ups","duration":40,"date":"2022-10-09","_id":"6345f5f457dd9608dee16431"}
Immediately after newExercise.save(function(err, data) {
I put
console.log(`err: ${err}`);
console.log(`data:${data}:`);
console.log(`id: ${id}`);
and these are the results:
err: null
data:{
userid: '6345930745dc28528ae508f7',
description: 'Press-ups',
duration: 40,
date: '2022-10-09',
_id: new ObjectId("6345f5f457dd9608dee16431"),
__v: 0
}:
id: 6345930745dc28528ae508f7
I then coded
const d = new Date(data.date);
res.json({ username : username,
description: description,
duration : data.duration,
date : d.toDateString(),
_id : id
});
and this is the result
{"username":"Alan","description":"Press-ups","duration":40,"date":"Sun Oct 09 2022","_id":"6345930745dc28528ae508f7"}
I also tried changing the _id : id
in the res.json
to _id : data.id
but this still won’t pass test 8.