how to get data from a relation graphql strapi?

309 Views Asked by At

I am doing a query that returns me a list of reservations according to a month and year. I get that result but these reservations are for a parking lot, but I only get the parking id.

How could I get the data for that parking lot?

  try {
    
      const user = ctx.state.user;
      const propietario = await strapi.services["propietario"].findOne({
        usuario: user.id,
      });
      const _paramsContainer = ctx.params._input || ctx.query;
      if (!propietario) {
        console.log('no existe');
        return;
      }
      const month = Number(_paramsContainer.month); //graphql queries
      const year = Number(_paramsContainer.year); //graphql queries
      const estacionamientosTemp = propietario["estacionamientos"];
      const estacionamientosID = estacionamientosTemp.map((e) => e.id);
      const reservas = await strapi.models["reserva"].find({
        estacionamiento: {
          $in: estacionamientosID,
        },

        fechaHoraInicio: {
          $gte: new Date(year, month, 1).toISOString(), //Primer día del mes
          $lt: new Date(year, month + 1, 1).toISOString(), //Primer día del siguiente mes
        },
        estado:"FINALIZADO"
      });

      console.log('RESERVAS',reservas);
      
    
  return{
    reservas:reservas
  }

    } catch (error) {
      console.log(error);
    }
0

There are 0 best solutions below