So the following code is functional, just one function with variation of specs, but I am kind of suspicious, I believe it looks ugly specially with the callback, it really needs refactoring, any ideas on how it can be refactored to be maintainable and overcome flaws?
await rps_id.map((rp_id) => {
return new Promise((resolve, reject) => {
Part.Model.updateOne({
_id: rp_id
}, {
invoiceId: invoice._id
}).then(function(result) {
return resolve();
})
.catch(() => {
reject();
});
});
});
this is the rest of the code: https://codepen.io/0xf10yd/pen/PopRWpz
I'd appreciate your help a lot, thanks in advance