const async = require("async");
const triggerPush = require("../services/push.service");
class MassPusher{
constructor(listOfTokens,pushData){
this.pushData=pushData;
this.success_tokens=[];
this.failure_tokens=[];
this.invokeOperation(listOfTokens);
}
invokeOperation = (listOfTokens) => {
async.each(listOfTokens,this.sendMassPush,(err,info)=>{
if(err)
console.log(this.failure_tokens,'error');
else
console.log(this.success_tokens,'success');
});
}
sendMassPush = (token, callback) =>{
this.pushData.to = token;
async.waterfall([
(callback)=>{
triggerPush(this.pushData)
.then(()=>{
this.success_tokens.push(token);
callback();
})
.catch(()=>{
this.failure_tokens.push(token);
callback();
})
}
],
function (){
callback();
})
}
}
module.exports = MassPusher;