filter contact before booking
This commit is contained in:
@@ -7,22 +7,38 @@ const mongoManager = new MongoManager();
|
||||
|
||||
let excelUtil = new ExcelUtil();
|
||||
let contactList = excelUtil.readContacts()
|
||||
mongoManager.connect().then(r =>
|
||||
let collectionName = formatDate(new Date())
|
||||
|
||||
android.devices().then((devices) => {
|
||||
let segmentNumber = contactList.length / devices.length;
|
||||
for (let i = 0; i < devices.length; i++) {
|
||||
startWithList(contactList.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i]);
|
||||
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;
|
||||
}
|
||||
|
||||
mongoManager.connect().then(r => {
|
||||
filterAlreadyBookedContacts(contactList).then(listToBook => {
|
||||
console.log(listToBook.length)
|
||||
android.devices().then((devices) => {
|
||||
let segmentNumber = listToBook.length / devices.length;
|
||||
for (let i = 0; i < devices.length; i++) {
|
||||
startWithList(contactList.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i]);
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
// Connect to the device.
|
||||
|
||||
async function needToBook(contact, mongoManager) {
|
||||
let collectionName = formatDate(new Date())
|
||||
let alreadBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName)
|
||||
let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName)
|
||||
let toReturn = true;
|
||||
await alreadBooked.forEach((bookedItem) => {
|
||||
await alreadyBooked.forEach((bookedItem) => {
|
||||
if (bookedItem.email === contact.mail) {
|
||||
toReturn = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user