filter blacklisted items before booking
This commit is contained in:
+14
-1
@@ -13,6 +13,17 @@ let collectionName = formatDate(new Date())
|
|||||||
async function filterAlreadyBookedContacts(contactList) {
|
async function filterAlreadyBookedContacts(contactList) {
|
||||||
let alreadyBookedContacts = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
|
let alreadyBookedContacts = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
|
||||||
let contactsToBook = [];
|
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) => {
|
contactList.forEach((contact) => {
|
||||||
let needToBook = true;
|
let needToBook = true;
|
||||||
alreadyBookedContacts.forEach((acceptedItem) => {
|
alreadyBookedContacts.forEach((acceptedItem) => {
|
||||||
@@ -134,7 +145,8 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
mongoManager.connect().then(r => {
|
mongoManager.connect().then(r => {
|
||||||
filterBlacklistedContacts(contactList).then(listWithoutBlackContact => {
|
filterAlreadyAccepteddContacts(contactList).then(notAcceptedContacts => {
|
||||||
|
filterBlacklistedContacts(notAcceptedContacts).then(listWithoutBlackContact => {
|
||||||
filterAlreadyBookedContacts(listWithoutBlackContact).then(listToBook => {
|
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) => {
|
||||||
@@ -152,6 +164,7 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user