manage accepted appointments

This commit is contained in:
2022-10-16 23:41:20 +02:00
parent b27cf3c806
commit c79c45db8a
6 changed files with 49 additions and 13 deletions
+21 -5
View File
@@ -6,6 +6,7 @@ const alert = require('alert');
const mongoManager = new MongoManager();
const SEVEN_DAYS_IN_S = 3600 * 24 * 7;
const THIRTY_DAYS_IN_S = 3600 * 24 * 30;
let excelUtil = new ExcelUtil();
let collectionName = formatDate(new Date())
@@ -24,8 +25,10 @@ async function filterAlreadyBookedContacts(contactList) {
// Connect to the device.
async function needToBook(contact, mongoManager) {
let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName)
let blackListItems = await mongoManager.getAllBlackedListItems()
console.log("check contact with email " + contact.mail)
let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
let blackListItems = await mongoManager.getAllBlackedListItems();
let alreadyAcceptedItems = await mongoManager.getAllAcceptedAppointments();
let needToBook = true;
await alreadyBooked.forEach((bookedItem) => {
if (bookedItem.email === contact.mail) {
@@ -36,12 +39,25 @@ async function needToBook(contact, mongoManager) {
if (needToBook) {
await blackListItems.forEach((blackListItem) => {
if (blackListItem.mail === contact.mail) {
console.log("=====handle blacklist item====")
console.log("=====handle blacklist item====");
console.log("update_at_s is " + blackListItem.update_at_in_s)
console.log("email is " + blackListItem.mail)
console.log("black list email is " + blackListItem.mail)
needToBook = blackListItem.update_at_in_s + SEVEN_DAYS_IN_S <= (new Date()) / 1000;
if (!needToBook) {
console.log("skip")
console.log("contact in blacklist -->skip");
}
}
})
}
if (needToBook) {
await alreadyAcceptedItems.forEach((acceptedItem) => {
if (acceptedItem.email === contact.mail) {
console.log("=====handle already accepted item====");
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");
}
}
})