Back End Development and APIs Projects - Exercise Tracker

Conte-nos o que está acontecendo:
Hello,
I’m having problems with the last test of this project, I’ve already tried to do it in some ways but it’s not accepted in the test.
Could someone take a look at the code. I appreciate it.

O(s) link(s) para seu projeto

solution: https://boilerplate-project-exercisetracker--juliohebert.repl.co

Informações de seu navegador:

Agente de usuário: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36

Desafio: Projetos de APIs e desenvolvimento de back-end - Registrador de exercícios

Link para o desafio:

My friend helped, I was passing the wrong argument. It is necessary to change the ‘limit’ argument to ‘Int’


[details="Summary"]
app.get("/api/users/:_id/logs", (req, res) => {
  const userId = req.params._id;
  // Obter os parâmetros da consulta
  const from = req.query.from;
  const to = req.query.to;
  const limit = req.query.limit;
  // Obter os parâmetros da consulta
  User.findById(userId, (err, user) => {
    if (err) {
      return res.json({ error: err.message });
    }
    let query = { "username": user.username };
    // Aplicar filtro de data 'from' se fornecido
    if (from) {
      query.date = { $gte: new Date(from) };
    } 
    // Aplicar filtro de data 'to' se fornecido
    if (to) {
      if (!query.date) {
        query.date = {};
      }
      query.date.$lte = new Date(to);
    }
    // Consulta limitada se 'limit' for fornecido
    const limitNumber = (limit) => {
      const x = parseInt(limit, 10);
      if (!isNaN(x)) {
        return x;
      } else {
        return 0;
      }
    }
    ////////////////////////    
    Exercise.find(query)
      .limit(limitNumber(limit))
      .exec((err, exercises) => {
        if (err) {
          return res.json({ error: err.message });
        }
        res.json({
          "username": user.username,
          "count": exercises.length,
          "_id": user._id,
          "log": exercises.map(x => ({
            "description": x.description,
            "duration": x.duration,
            "date": x.date.toDateString()
          }))
        });
      });
  });
});
[/details]

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.