I'm trying to send some pushes to users when a 'invitation' is written in Realtime DB.
When the cloud function detects the creation of the invitation is triggered, and recovers the users list to ve invited (id's).
Once I get this id's I have to recover the user info for each id, in order to get some info like language, fcmTokens, etc..
Reading some SO questions I saw that I have to create a reference to the "call" like:
admin.database().ref(`/user/${userId}`).once('value')
Then store it in an array and call with Promise.all()
var userPromises = [];
for (var i = 0;i<usersInRange.length; i++) {
var userId = usersInRange[i];
userPromises[i] = admin.database().ref(`/user/${userId}`).once('value');
}
Promise.all(userPromises).then(results => {
...
})
And here is where I need help.
I'm having some problems , because if Promise.all() fails in retrieving some user, it stops, and don't read the other id's.
There is a way to do it "one by one" to avoid Promise.all() stop?