filter blacklisted items before booking

This commit is contained in:
2022-11-17 15:25:42 +01:00
parent cb4823ff69
commit e5574b5686
+14 -1
View File
@@ -13,6 +13,17 @@ let collectionName = formatDate(new Date())
async function filterAlreadyBookedContacts(contactList) {
let alreadyBookedContacts = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
let contactsToBook = [];
contactList.forEach((contact) => {
if (alreadyBookedContacts.find((bookedContact) => bookedContact.email === contact.mail) === undefined) {
contactsToBook.push(contact)
}
})
return contactsToBook;
}
async function filterAlreadyAccepteddContacts(contactList) {
let alreadyBookedContacts = await mongoManager.getAllAcceptedAppointments();
let contactsToBook = [];
contactList.forEach((contact) => {
let needToBook = true;
alreadyBookedContacts.forEach((acceptedItem) => {
@@ -134,7 +145,8 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
return
}
mongoManager.connect().then(r => {
filterBlacklistedContacts(contactList).then(listWithoutBlackContact => {
filterAlreadyAccepteddContacts(contactList).then(notAcceptedContacts => {
filterBlacklistedContacts(notAcceptedContacts).then(listWithoutBlackContact => {
filterAlreadyBookedContacts(listWithoutBlackContact).then(listToBook => {
console.log("number of contacts to book:" + listToBook.length)
android.devices().then((devices) => {
@@ -152,6 +164,7 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
})
}
)
})
}
)
}