Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
Array not returning from a router

I'm having some trouble getting some values from my database via express. On my server, I have this router call:

router.get('/list/:id', TokenController.isAValidToken, async (req, res) => {
    const { cardID } = req.query;

    try {
        if (cardID != null) {
            ...
        } else {
            const cards = await CardsController.getCardsForList(req.params.id);
            const orderItems = await OrderItemController.getOrderItemsForCardsInList(cards, req.params.id);
            console.log(orderItems); // <- This prints an array with the info I need
            res.json(orderItems);
        }
    } catch (error) {
        ...
    }
});

My getOrderItemsForCardsInList function has this:

static async getOrderItemForCardInList(cardID, listID) {
   return OrderItem.find({ card: cardID, list: listID }).exec();
}

static async getOrderItemsForCardsInList(cards, listID) {
   return Promise.all(cards.map((card) => OrderItemController.getOrderItemForCardInList(card, listID)));
}

On my client, I call the router function like this:

async function getOrderItemsForCardsInList(listID) {
    const token = await getToken();
    const response = await fetch(`${basePath}/order/list/${listID}`, {
        method: 'GET',
        headers: getTokenAuthHeaders(token)
    });

    return response.json();
}

export default function useOrderItemsForCardsInList(cards) {
    const { listID } = useParams();

    return useQuery(['order', ...cards], () => {
        if (listID != null) {
            return getOrderItemsForCardsInList(listID);
        } else {
            throw Error('No list id defined');
        }
    });
}

And I call that custom hook over here:

const { orderdata } = useOrderItemsForCardsInList(cards.map((card) => card !== null && card._id));
console.log('Data', orderdata);

The problem is that orderdata is printing undefined, meaning that the values are not getting returned as they should, my theory is that probably I'm messing something up in my useOrderItemsForCardsInList custom hook.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda