From 85c2102c006661b217157066eaf88e7859864d2a Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Thu, 17 Nov 2022 14:55:50 +0100 Subject: [PATCH] filter blacklisted items before booking --- src/appointment.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/appointment.js b/src/appointment.js index ec86aa9..3d6635e 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -25,8 +25,19 @@ async function filterBlacklistedContacts(contactList) { let blackListedContacts = await mongoManager.getAllBlackedListItems(collectionName); let contactsToBook = []; 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) + } 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;