I need help in this code

could some one tell me whats wrong in this?
I’m not able to get :-

Each item in the log array that is returned from GET /api/users/:id/logs is an object that should have a description , duration , and date properties.

and

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.

right, pls someone just lend me a hand.

Here is my code…

const express = require('express')
const app = express()
const mongoose = require('mongoose')
const cors = require('cors')
const bodyParser = require('body-parser')
require('dotenv').config()

app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())

mongoose.connect(process.env.URI, { useNewUrlParser: true, useUnifiedTopology: true });

console.log(mongoose.connection.readyState);

const exerciseSchema = new mongoose.Schema({
        description: {type: String, required: true},
        count: Number ,
        duration: {type: Number, required: true},
        date: Date
})
const Exercise = new mongoose.model("exercise", exerciseSchema)

const personSchema = new mongoose.Schema({
        username: { type: String, unique: true, required: true },
        log: [exerciseSchema]
});
const Person = mongoose.model("Person", personSchema);

app.use(cors())
app.use(express.static('public'))
app.get('/', (req, res) => {
  res.sendFile(__dirname + '/views/index.html')
});

app.post('/api/users', (req,res) => {
        console.log(req.body);
        const newPerson = new Person({username: req.body.username})
        newPerson.save((err, data) => {
                if(err){
                    res.send("User Name Taken")
                } else{
                    res.json({"username": data.username, "_id": data.id})
                }
        })
});

app.get('/api/users', (req, res) => {
        Person.find({}, (err, data) => {
                if(!err){
                        res.json(data)
                } else {
                        console.log("error")
                }
        });
});

app.post('/api/users/:_id/exercises', bodyParser.urlencoded({extended: false}), (req, res) => {
        let newExercise = new Exercise({
                description: req.body.description,
                duration: parseInt(req.body.duration),
                date: req.body.date === '' ? new Date().toDateString() : new Date(req.body.date).toDateString()
        })

        var helid = req.params._id
// var date = req.body.date === '' ? new Date().toDateString() : new Date(req.body.date).toDateString();
        Person.findByIdAndUpdate(
                helid,
                {$push: {log: newExercise}},
                {new: true},
                (err, data) => {
                        if(err){
                                "USER NOT FOUND"
                        } else if(req.body.date === ''){
                                res.json({
                                        username: data.username,
                                        description: req.body.description,
                                        duration: parseInt(req.body.duration),
                                        date: new Date().toDateString(),
                                        _id: data._id
                                })
                        } else {
                            res.json({
                                        username: data.username,
                                        description: req.body.description,
                                        duration: parseInt(req.body.duration),
                                        date: new Date(req.body.date).toDateString(),
                                        _id: data._id
                                })
                        }
                }
        )
});


app.get('/api/users/:_id/logs', (req, res) => {
        const helid = req.params._id
        Person.findById(helid, (err, data) => {
                if(err){
                        res.json("USER NOT FOUND")
                } else{
                        res.json({
                                username: data.username,
                                _id: data._id,
                                count: data.log.length,
                                log: data.log ,
                                "log.date" : new Date(data.log.date).toDateString()      
                        })
                }
        })
});

const listener = app.listen(process.env.PORT || 3000, () => {
  console.log('Your app is listening on port ' + listener.address().port)
});

THANK YOU

Did you solve this?
I am getting exact same problem :frowning: