Exercise Tracker - Second last user story not passing

Hello everyone

I need assistance here - I have tried several ways but only the second last requirement is failing : " 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."

When I console log “typeof” on one of the date properties inside the log array I get “string” on the console. I do not understand why this is failing. All other user stories are passing.

My code also converts the dates into a string using the toDateString() method as recommended in the project.

Your code so far
const express = require(‘express’);
const bodyParser = require(‘body-parser’);
const mongoose = require(‘mongoose’);
const app = express();
const cors = require(‘cors’);
require(‘dotenv’).config();

app.use(bodyParser.urlencoded({ extended: “false” }));
app.use(cors());
app.use(express.static(‘public’));
app.get(’/’, (req, res) => {
res.sendFile(__dirname + ‘/views/index.html’)
});

const mySecret = process.env[‘MONGO_URI’]
mongoose.connect(mySecret, { useNewUrlParser: true, useUnifiedTopology: true });

const Schema = mongoose.Schema;
const logSchema = new Schema({ username: { type: String, required: true }, log: [Object] });
const sessionSchema = new Schema({description:{type: String, required: true}, duration: {type: Number, required: true},
date: String})

const Activity = mongoose.model(“Activity”, logSchema);
const Session = mongoose.model(‘Session’, sessionSchema);

app.post(’/api/users’, function(req, res) {

const username = req.body.username;
const run = new Activity({ username: username });
run.save(function(err, data) {
if (err) return console.error(err);
res.json({ username: data.username, _id: data.id })
});

});

app.get(’/api/users’, function(req, res) {

Activity.find({}, function(err, data) {
if (err) return console.log(err);

res.json(data);

})

});

app.post(’/api/users/:_id/exercises’,(req,res)=>{
const id = req.params._id;
const inputDate = req.body.date;
let date = ‘’;

if (inputDate == “”){
date = new Date().toDateString();
} else {
date = new Date(inputDate).toDateString();
}

const newSes = new Session({description: req.body.description,
duration: parseInt(req.body.duration),
date: date});

Activity.findByIdAndUpdate(id,
{$push:{log: newSes}},
{new: true},
function (err,data){

if(err) return console.log(err);

res.json({username: data.username, description: newSes.description, duration: newSes.duration, date: newSes.date, _id: data._id});
});

});

app.get(’/api/users/:_id/logs’, function(req,res){

Activity.findById(req.params._id, function(err,data){
if (err) return console.error(err);

let log = data.log;

if(req.query.from || req.query.to){
let fromDate = new Date(0);
let toDate = new Date();

if(req.query.from) fromDate = new Date(req.query.from);
if(req.query.to) toDate = new Date(req.query.to);

fromDate = fromDate.getTime();
toDate = toDate.getTime();

log = log.filter(function(session){
let sessionDate = new Date(session.date).getTime();

return sessionDate >= fromDate && sessionDate <= toDate;

})

}

if(req.query.limit){
log = log.slice(0,req.query.limit)
}

res.json({username: data.username, count: log.length, _id: data._id, log: log});
//console.log(typeof log[0].date);
});

});

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36

Challenge: Exercise Tracker

Link to the challenge: