test check blacklist
This commit is contained in:
+11
-1
@@ -5,7 +5,7 @@ const {MongoManager, formatDate} = require("./workers/mongo_manager");
|
||||
const alert = require('alert');
|
||||
|
||||
const mongoManager = new MongoManager();
|
||||
|
||||
const SEVEN_DAYS_IN_S = 3600 * 24 * 7;
|
||||
let excelUtil = new ExcelUtil();
|
||||
let collectionName = formatDate(new Date())
|
||||
|
||||
@@ -25,6 +25,7 @@ async function filterAlreadyBookedContacts(contactList) {
|
||||
|
||||
async function needToBook(contact, mongoManager) {
|
||||
let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName)
|
||||
let blackListItems = await mongoManager.getAllBlackedListItems()
|
||||
let toReturn = true;
|
||||
await alreadyBooked.forEach((bookedItem) => {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ const mongoManager = new MongoManager();
|
||||
mongoManager.connect().then(r => {
|
||||
let contact = new ContactPojo("0649614591", "1234567890", "PAN", "Lei", "panleicim@gmail.com")
|
||||
let commandPage = new CommandorPage(contact, null, mongoManager)
|
||||
commandPage.saveToBlackList().then(r => {
|
||||
commandPage.deleteFromBlackList().then(r => {
|
||||
console.log("saved to db")
|
||||
})
|
||||
|
||||
|
||||
@@ -371,6 +371,7 @@ class CommandorPage {
|
||||
let reserve = ReserveResultPojo.create_from_contact(this.contact, id, this.page.url(), this.choosedStore, publishType);
|
||||
reserve.source_from = this.device.model();
|
||||
await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict())
|
||||
await this.deleteFromBlackList()
|
||||
this.isTerminated = true
|
||||
}
|
||||
|
||||
@@ -379,6 +380,10 @@ class CommandorPage {
|
||||
this.isTerminated = true
|
||||
}
|
||||
|
||||
async deleteFromBlackList() {
|
||||
await this.mongoManager.removeFromBlackList(this.contact)
|
||||
}
|
||||
|
||||
async getErrors() {
|
||||
if (this.page.url() === BLANK_URL) {
|
||||
this.isTerminated = true;
|
||||
|
||||
@@ -49,6 +49,15 @@ class MongoManager {
|
||||
async saveBlackListToDb(contact) {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user