filter blacklisted items before booking

This commit is contained in:
2022-11-17 14:15:52 +01:00
parent 21a3834a47
commit 3776e73c6f
+29 -15
View File
@@ -21,6 +21,17 @@ async function filterAlreadyBookedContacts(contactList) {
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) {
console.log("check contact with email " + contact.mail)
let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
@@ -99,21 +110,24 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
return
}
mongoManager.connect().then(r => {
filterAlreadyBookedContacts(contactList).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:" + listToBook.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);
}
})
})
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:" + listToBook.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);
}
})
})
}
)
}
)
}