Tengo una matriz de ID de categoría en orden, tengo que hacer un mapa y buscar los elementos de estas categorías y, al final, mantener el orden original de la matriz.
lo que he estado haciendo:
const info = [] Promise.all(categoryItem.next_steps.map((next_step) => { return categoryItemSvcV2.getAllItensNoOrderByCategoryId(next_step.category, idpage) .then((result) => { info.push(result) }) })).then(() => { res.json({ success: true, info }) })el categoryItem.next_steps es la matriz de categoryIds en orden, sin embargo, cada vez que llamo a esta función, se muestra en un orden
Promise.all hace esto fuera de la caja , no traiga su propia matriz:
Promise.all(categoryItem.next_steps.map(next_step => categoryItemSvcV2.getAllItensNoOrderByCategoryId(next_step.category, idpage) )).then(info => { // ^^^^ res.json({ success: true, info }) });Como está usando Promise.all, no necesita crear una matriz separada. Mirando su código anterior, esto debería funcionar
const values = await Promise.all( categoryItem.next_steps.map((next_step) => categoryItemSvcV2.getAllItensNoOrderByCategoryId(next_step.category, idpage) ) ); res.json({ success: true, values });