filter blacklisted items before booking

This commit is contained in:
2022-11-17 14:15:52 +01:00
parent 21a3834a47
commit 3776e73c6f
+15 -1
View File
@@ -21,6 +21,17 @@ async function filterAlreadyBookedContacts(contactList) {
return contactsToBook; return contactsToBook;
} }
async function filterBlacklistedContacts(contactList) {
let blackListedContacts = await mongoManager.getAllBlackedListItems(collectionName);
let contactsToBook = [];
contactList.forEach((contact) => {
if (blackListedContacts.find((bookedContact) => bookedContact.email === contact.mail) === undefined) {
contactsToBook.push(contact)
}
})
return contactsToBook;
}
async function needToBook(contact, mongoManager) { async function needToBook(contact, mongoManager) {
console.log("check contact with email " + contact.mail) console.log("check contact with email " + contact.mail)
let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName); let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
@@ -99,7 +110,8 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
return return
} }
mongoManager.connect().then(r => { mongoManager.connect().then(r => {
filterAlreadyBookedContacts(contactList).then(listToBook => { filterBlacklistedContacts(contactList).then(listWithoutBlackContact => {
filterAlreadyBookedContacts(listWithoutBlackContact).then(listToBook => {
console.log("number of contacts to book:" + listToBook.length) console.log("number of contacts to book:" + listToBook.length)
android.devices().then((devices) => { android.devices().then((devices) => {
if (devices.length === 0) { if (devices.length === 0) {
@@ -117,5 +129,7 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
} }
) )
} }
)
}
module.exports = startBookWithNumbers module.exports = startBookWithNumbers