test check blacklist

This commit is contained in:
2022-10-13 16:41:48 +02:00
parent de2fa6f518
commit becea669ac
4 changed files with 26 additions and 2 deletions
+11 -1
View File
@@ -5,7 +5,7 @@ const {MongoManager, formatDate} = require("./workers/mongo_manager");
const alert = require('alert'); const alert = require('alert');
const mongoManager = new MongoManager(); const mongoManager = new MongoManager();
const SEVEN_DAYS_IN_S = 3600 * 24 * 7;
let excelUtil = new ExcelUtil(); let excelUtil = new ExcelUtil();
let collectionName = formatDate(new Date()) let collectionName = formatDate(new Date())
@@ -25,6 +25,7 @@ async function filterAlreadyBookedContacts(contactList) {
async function needToBook(contact, mongoManager) { async function needToBook(contact, mongoManager) {
let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName) let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName)
let blackListItems = await mongoManager.getAllBlackedListItems()
let toReturn = true; let toReturn = true;
await alreadyBooked.forEach((bookedItem) => { await alreadyBooked.forEach((bookedItem) => {
if (bookedItem.email === contact.mail) { if (bookedItem.email === contact.mail) {
@@ -32,6 +33,15 @@ async function needToBook(contact, mongoManager) {
} }
} }
) )
await blackListItems.forEach((blackListItem) => {
console.log("=====handle blacklist item====")
console.log("update_at_s is " + blackListItem.update_at_in_s)
console.log("email is " + blackListItem.mail)
toReturn = blackListItem.update_at_in_s <= (new Date()) + SEVEN_DAYS_IN_S;
if (!toReturn) {
console.log("skip")
}
})
return toReturn return toReturn
} }
+1 -1
View File
@@ -7,7 +7,7 @@ const mongoManager = new MongoManager();
mongoManager.connect().then(r => { mongoManager.connect().then(r => {
let contact = new ContactPojo("0649614591", "1234567890", "PAN", "Lei", "panleicim@gmail.com") let contact = new ContactPojo("0649614591", "1234567890", "PAN", "Lei", "panleicim@gmail.com")
let commandPage = new CommandorPage(contact, null, mongoManager) let commandPage = new CommandorPage(contact, null, mongoManager)
commandPage.saveToBlackList().then(r => { commandPage.deleteFromBlackList().then(r => {
console.log("saved to db") console.log("saved to db")
}) })
+5
View File
@@ -371,6 +371,7 @@ class CommandorPage {
let reserve = ReserveResultPojo.create_from_contact(this.contact, id, this.page.url(), this.choosedStore, publishType); let reserve = ReserveResultPojo.create_from_contact(this.contact, id, this.page.url(), this.choosedStore, publishType);
reserve.source_from = this.device.model(); reserve.source_from = this.device.model();
await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict()) await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict())
await this.deleteFromBlackList()
this.isTerminated = true this.isTerminated = true
} }
@@ -379,6 +380,10 @@ class CommandorPage {
this.isTerminated = true this.isTerminated = true
} }
async deleteFromBlackList() {
await this.mongoManager.removeFromBlackList(this.contact)
}
async getErrors() { async getErrors() {
if (this.page.url() === BLANK_URL) { if (this.page.url() === BLANK_URL) {
this.isTerminated = true; this.isTerminated = true;
+9
View File
@@ -49,6 +49,15 @@ class MongoManager {
async saveBlackListToDb(contact) { async saveBlackListToDb(contact) {
return await this.db.collection(BLACK_LIST_COLLECTION_NAME).replaceOne({'_id': contact.mail,}, contact, {upsert: true}) return await this.db.collection(BLACK_LIST_COLLECTION_NAME).replaceOne({'_id': contact.mail,}, contact, {upsert: true})
} }
async removeFromBlackList(contact) {
const query = {_id: contact.mail};
await this.db.collection(BLACK_LIST_COLLECTION_NAME).deleteOne(query);
}
async getAllBlackedListItems() {
return await this.db.collection(BLACK_LIST_COLLECTION_NAME).find().toArray()
}
} }