filter blacklisted items before booking

This commit is contained in:
2022-11-17 15:25:42 +01:00
parent cb4823ff69
commit e5574b5686
+30 -17
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,24 +145,26 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
return
}
mongoManager.connect().then(r => {
filterBlacklistedContacts(contactList).then(listWithoutBlackContact => {
filterAlreadyBookedContacts(listWithoutBlackContact).then(listToBook => {
console.log("number of contacts to book:" + listToBook.length)
android.devices().then((devices) => {
if (devices.length === 0) {
alert("未找到连接的设备");
return
}
let segmentNumber = listToBook.length / devices.length;
console.log("connected device number:" + devices.length)
console.log("segmentNumber:" + segmentNumber)
for (let i = 0; i < devices.length; i++) {
startWithList(listToBook.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore, audioAnalyse, alertBeep);
}
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) => {
if (devices.length === 0) {
alert("未找到连接的设备");
return
}
let segmentNumber = listToBook.length / devices.length;
console.log("connected device number:" + devices.length)
console.log("segmentNumber:" + segmentNumber)
for (let i = 0; i < devices.length; i++) {
startWithList(listToBook.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore, audioAnalyse, alertBeep);
}
})
})
})
}
)
}
)
})
}
)
}