filter blacklisted items before booking

This commit is contained in:
2022-11-17 14:55:50 +01:00
parent 3776e73c6f
commit 85c2102c00
+12 -1
View File
@@ -25,8 +25,19 @@ async function filterBlacklistedContacts(contactList) {
let blackListedContacts = await mongoManager.getAllBlackedListItems(collectionName); let blackListedContacts = await mongoManager.getAllBlackedListItems(collectionName);
let contactsToBook = []; let contactsToBook = [];
contactList.forEach((contact) => { contactList.forEach((contact) => {
if (blackListedContacts.find((bookedContact) => bookedContact.email === contact.mail) === undefined) { let blackListedItem = blackListedContacts.find((bookedContact) => bookedContact.email === contact.mail)
if (blackListedItem === undefined) {
contactsToBook.push(contact) contactsToBook.push(contact)
} else {
console.log("=====handle blacklist item before booking====");
console.log("update_at_s is " + blackListedItem.update_at_in_s)
console.log("black list email is " + blackListedItem.mail)
let needToBook = blackListedItem.update_at_in_s + SEVEN_DAYS_IN_S <= (new Date()) / 1000;
if (!needToBook) {
console.log("contact in blacklist -->skip");
} else {
contactsToBook.push(contact)
}
} }
}) })
return contactsToBook; return contactsToBook;