From 3776e73c6f5dca179533eab88c333cf2aa02875c Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Thu, 17 Nov 2022 14:15:52 +0100 Subject: [PATCH] filter blacklisted items before booking --- src/appointment.js | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/appointment.js b/src/appointment.js index 7dd81bb..ec86aa9 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -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); + } + }) + }) + } + ) } ) }