Tell us what’s happening:
Hello everyone,
I am currently doing the Exercise Tracker Microservice project in the Backend Development & API’s certification. The app itself works fine. I have tested it multiple times to confirm, and the responses are exactly the same as the project requirements as well as the demo website.
The only issue I have is it seems all the tests related to the path api/users/:_id/logs
fail despite it returning the appropriate response (format’s correct, and the exercise logs that are returned conform to the &from
, &to
, and &count
queries. All other tests work fine. My endpoint code is below:
let initial;
let final;
let ct;
app.get('/api/users/:_id/logs', (req, res) => {
//path looks like /logs?from=date1&to=date2&limit=number
//setup
if(req.query.from){
initial = new Date(req.query.from)
}else{
initial = new Date('1970-01-01')
}
if(req.query.to){
final = new Date(req.query.to)
}else{
final = new Date()
}
if(req.query.limit){
ct = req.query.limit
}else{
ct = 1000
}
User.findById(req.params._id, (err, data) => {
let gotUsername = data.username;
if(!data){
console.log('user undefined.')
}else{
Exercise.find({userId: req.params._id, date: {$gte: initial, $lte: final}}).limit(ct).exec ((err, output) => {
let newOutput = output.map(o => (
{
description: o.description,
duration: o.duration,
date: o.date.toDateString()
}
))
res.send({username: gotUsername, _id: req.params._id, count: newOutput.length, log: newOutput})
})
}
})
})
No errors are generated when code runs, at least for me. Could someone else test it out to see if it works for them / spot what’s going on? My project link is below.
Thank you for your time.
Your project link(s)
solution: boilerplate-project-exercisetracker-5 - Nix (beta) Repl - Replit
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
Challenge: Back End Development and APIs Projects - Exercise Tracker
Link to the challenge: