I am begining in node and I have a problem, I need to do this only with promises by node versions, I need to make a comparison with the result of previous promises but dont works, it seems me that is code that is poorly structured, here the code thanks...
ListarUsuariosMaxDate.then(response => {
return ListaconCondicionProceso(response);
}).then(data2 => {
return filtrarPagos.then(data3 => {
let result = data3.filter(elem => data2.filter(elem2 => elem.user == elem2.user_id && elem.createdAt > elem2.maximo).length > 0);
return result;
}).then(data5 => {
console.log(data5)
})
})
})
the result (data5) is emtpy...sorry about the mistake...
I could do it something change and works, but I don't understand why. I had in my previous code with async and await this structure, and it worked:
async function comparacionTotalProceso(listaTotal, listaFiltrada) {
let result = listaFiltrada.filter(elem => listaTotal.filter(elem2 => elem.user == elem2.user_id && elem.createdAt > elem2.maximo).length > 0);
return result;
});
}
but now for node version, I need to change everything to promises and I did this:
...
.then(data2 => {
return filtrarPagos.then(data3 => {
let result = data2.map(elem => data3.map(elem2 => elem.user == elem2.user_id && elem.createdAt > elem2.maximo).length > 0? elem:null);
return result;
})
and finally works changed the filter for map and return elem, but I don't know why.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.