I have data passed to function where i need to check every object in array and return all promises , How can i pass same data to down in chaining so i can use for processing. Every promise is call to database to validate and insert data.
1- How to pass event
to all promises for further processing ?
2- How to check if all events processing is done , then next func can invoke ?
Ctrl.js
var data = [{
activityId: '1tgktxy',
variables: {
event: [Object]
},
priority: 0
},
{
activityId: '7tl07',
variables: {
caseIdFound: [{
type: Boolean,
value: true
}],
event: [Object]
},
priority: 0
},
{
activityId: '7tl07',
variables: {
caseIdFound: [{
type: Boolean,
value: true
}],
event: [Object]
},
priority: 0
},
]
function mainFunction(data) {
return Promise.all(data.map(function(element) {
var event = JSON.parse(element.variables.event.value);
return checkTicketNumber(event);
})
.then(function() {
return insertDataToLog();
}).
.then(function() {
return insertDataToResult();
})
.then(function() {
console.log('All task events processing is done');
// anotherFunction();
}).
}
var checkTicketNumber = new Promise(
function(resolve, reject) {
checkTicketCall(ticketNumber, function(err, response) {
resolve();
}):
});
// if caseIdFound is true then i want invoke thise promise
var insertDataToLog = new Promise(
function(resolve, reject) {
InsertCall(event.body, function(err, response) {
resolve();
}):
});
// if caseIdFound is true then i want invoke thise promise
var insertDatatoResult = new Promise(
function(resolve, reject) {
InsertCall(event.body, function(err, response) {
resolve();
}):
});
mainFunction(data);