Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
La matriz no regresa de un enrutador

Tengo problemas para obtener algunos valores de mi base de datos a través de Express. En mi servidor, tengo esta llamada de enrutador:

 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) { ... } });

Mi función getOrderItemsForCardsInList tiene esto:

 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))); }

En mi cliente, llamo a la función del enrutador así:

 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'); } }); }

Y llamo a ese gancho personalizado aquí:

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

El problema es que orderdata se está imprimiendo undefined , lo que significa que los valores no se devuelven como deberían, mi teoría es que probablemente esté estropeando algo en mi enlace personalizado useOrderItemsForCardsInList .

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!