filter blacklisted items before booking
This commit is contained in:
+26
-13
@@ -14,7 +14,19 @@ async function filterAlreadyBookedContacts(contactList) {
|
|||||||
let alreadyBookedContacts = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
|
let alreadyBookedContacts = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
|
||||||
let contactsToBook = [];
|
let contactsToBook = [];
|
||||||
contactList.forEach((contact) => {
|
contactList.forEach((contact) => {
|
||||||
if (alreadyBookedContacts.find((bookedContact) => bookedContact.email === contact.mail) === undefined) {
|
let needToBook = true;
|
||||||
|
alreadyBookedContacts.forEach((acceptedItem) => {
|
||||||
|
if (acceptedItem.email === contact.mail) {
|
||||||
|
console.log("=====handle already accepted item before booking====");
|
||||||
|
console.log("accepted_at is " + acceptedItem.accepted_at);
|
||||||
|
console.log("accepted email is " + acceptedItem.email);
|
||||||
|
needToBook = acceptedItem.accepted_at + THIRTY_DAYS_IN_S <= (new Date()) / 1000;
|
||||||
|
if (!needToBook) {
|
||||||
|
console.log("already accepted appointment --> skip");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (needToBook) {
|
||||||
contactsToBook.push(contact)
|
contactsToBook.push(contact)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -25,20 +37,21 @@ async function filterBlacklistedContacts(contactList) {
|
|||||||
let blackListedContacts = await mongoManager.getAllBlackedListItems();
|
let blackListedContacts = await mongoManager.getAllBlackedListItems();
|
||||||
let contactsToBook = [];
|
let contactsToBook = [];
|
||||||
contactList.forEach((contact) => {
|
contactList.forEach((contact) => {
|
||||||
let blackListedItem = blackListedContacts.find((bookedContact) => bookedContact.email === contact.mail)
|
let needToBook = true;
|
||||||
if (blackListedItem === undefined) {
|
blackListedContacts.forEach((blackListItem) => {
|
||||||
contactsToBook.push(contact)
|
if (blackListItem.mail === contact.mail) {
|
||||||
} else {
|
console.log("=====handle blacklist item before booking=====");
|
||||||
console.log("=====handle blacklist item before booking====");
|
console.log("update_at_s is " + blackListItem.update_at_in_s)
|
||||||
console.log("update_at_s is " + blackListedItem.update_at_in_s)
|
console.log("black list email is " + blackListItem.mail)
|
||||||
console.log("black list email is " + blackListedItem.mail)
|
needToBook = blackListItem.update_at_in_s + SEVEN_DAYS_IN_S <= (new Date()) / 1000;
|
||||||
let needToBook = blackListedItem.update_at_in_s + SEVEN_DAYS_IN_S <= (new Date()) / 1000;
|
if (!needToBook) {
|
||||||
if (!needToBook) {
|
console.log("contact in blacklist -->skip");
|
||||||
console.log("contact in blacklist -->skip");
|
}
|
||||||
} else {
|
}
|
||||||
|
if (needToBook) {
|
||||||
contactsToBook.push(contact)
|
contactsToBook.push(contact)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
})
|
||||||
return contactsToBook;
|
return contactsToBook;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user