Changed logic for checkup.For testing.

This commit is contained in:
Naida Vatric
2020-01-24 01:01:10 +01:00
parent b2c102bc1a
commit 40509d2836
6 changed files with 37 additions and 8 deletions

View File

@@ -14,6 +14,8 @@ const DEFAULT_TIMEZONE = "Europe/Sarajevo";
const CRAWLER_INTERVAL = parseInt(process.env.CRAWLER_INTERVAL) || 60;
const STOP_CRAWLER = !!parseInt(process.env.STOP_CRAWLER);
const CHECK_UP_DAYS = parseInt(process.env.CHECK_UP_DAYS) || 10;
const AWS_EMAIL_CONFIG = {
REGION: process.env.AWS_REGION || "",
CREDENTIALS: {
@@ -42,5 +44,6 @@ module.exports = {
MAX_REAL_ESTATES_IN_EMAIL,
MAX_REAL_ESTATES_IN_FIRST_EMAIL,
PRINT_CRAWLER_DEBUG,
API_MAP_KEY
API_MAP_KEY,
CHECK_UP_DAYS
};

View File

@@ -1,5 +1,6 @@
"use strict";
const db = require("../../models/index");
const { CHECK_UP_DAYS } = require("../../config/appConfig");
const findRealEstatesForSearchRequest = async searchRequestId => {
const query = {
@@ -41,8 +42,27 @@ const findNotNotifiedMatches = async () => {
return matchingRecords;
};
const findAllRequestsForCheckUp = async () => {
//First we find IDs of search request that don't need to be emailed for check up - to EXCLUDE
//The ones that received notification for real estate CHECK_UP_DAYS days from now
const date = new Date();
const checkUpDate = date.getDate() - CHECK_UP_DAYS;
date.setDate(checkUpDate);
const dateQuery = {
createdAt: {
[Op.gte]: date
}
};
const excludedRequests = await db.SearchRequestMatch.findAll({
attributes: ["searchRequestId"],
where: dateQuery
});
const query = {
subscribed: true
subscribed: true,
id: {
[Op.notIn]: excludedRequests
}
};
const allRequestsForCheckUp = await db.SearchRequest.findAll({
where: query

View File

@@ -1,6 +1,6 @@
"use strict";
const { checkUpNotifyAll } = require("../services/notificationService");
const { checkUpNotify } = require("../services/notificationService");
//For testing pursposes
(async () => {
await checkUpNotifyAll();
await checkUpNotify();
})();

View File

@@ -113,7 +113,7 @@ const notifyRequestsWithDailyOption = async () => {
await notifyMatches(matches, true);
};
const checkUpNotifyAll = async () => {
const checkUpNotify = async () => {
const searchRequestsForCheckUp = await findAllRequestsForCheckUp();
const asyncSendEmailActions = [];
@@ -134,5 +134,5 @@ module.exports = {
notifyForNewRealEstates,
notifyForNewSearchRequest,
notifyRequestsWithDailyOption,
checkUpNotifyAll
checkUpNotify
};