Back End Development and APIs Projects - Exercise Tracker

hello exeryone, im stuck at passing the last test in this project, help me please
the cause is because Test time out

my replit repo

solution: boilerplate-project-exercisetracker - Nix (beta) Repl - Replit

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:103.0) Gecko/20100101 Firefox/103.0

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

I don’t really know what the issue is, but, it may happen due to slow connections on the net. So, the general idea is that you try the tests at a later time or find a way to run it faster (e.g., run using Glitch, have a database with location closer to you). I also suggest looking for any errors in the replit console and browser console.

That said, just a suggestion regarding your code from the function populateTheLog. This is refactoring, little bit:

Your code:

    let findAllExercises;
	
    if (from !== undefined && to !== undefined){
      const fromUnix = new Date(from).getTime();
      const toUnix = new Date(to).getTime();
      findAllExercises = await Exercise.find({user_id: req.user._id, $and: [ {dateUnix:{$gt:fromUnix}}, {dateUnix:{$lt:toUnix}} ] }).select({ _id: 0, __v: 0 , user_id: 0, dateUnix: 0});
    } else if (from !== undefined && to === undefined){
      const fromUnix = new Date(from).getTime();
      findAllExercises = await Exercise.find({user_id: req.user._id, dateUnix: {$gt:fromUnix} }).select({ _id: 0, __v: 0 , user_id: 0, dateUnix: 0});
    } else {
      findAllExercises =  await Exercise.find({user_id: req.user._id}).select({ _id: 0, __v: 0 , user_id: 0, dateUnix:0});
    }

Refactored:

let query = { user_id: req.user._id };
let dateQuery;

if (from !== undefined && to !== undefined) {
      const fromUnix = new Date(from).getTime();
      const toUnix = new Date(to).getTime();
      dateQuery =  { dateUnix: { $gte: fromUnix, $lte: toUnix } };
} else if (from !== undefined && to === undefined) {
      const fromUnix = new Date(from).getTime();
      dateQuery = { dateUnix: { $gte: fromUnix } };
} else if (from === undefined && to !== undefined) {
      const toUnix = new Date(to).getTime();
      dateQuery = { dateUnix: { $lte: toUnix } };
}
else {
      dateQuery = { };
}

query = Object.assign(query, dateQuery);

let findAllExercises = await Exercise.find(query).select({ _id: 0, __v: 0 , user_id: 0, dateUnix: 0 });