Changed to send email only to some users.

This commit is contained in:
Naida Vatric
2020-01-24 16:04:28 +01:00
parent 40509d2836
commit 470f53d29b
3 changed files with 13 additions and 10 deletions

View File

@@ -1,5 +1,7 @@
"use strict";
const db = require("../../models/index");
const sequelize = require("sequelize");
const Op = sequelize.Op;
const { CHECK_UP_DAYS } = require("../../config/appConfig");
const findRealEstatesForSearchRequest = async searchRequestId => {
@@ -53,11 +55,18 @@ const findAllRequestsForCheckUp = async () => {
}
};
const excludedRequests = await db.SearchRequestMatch.findAll({
const excludedMatches = await db.SearchRequestMatch.findAll({
attributes: ["searchRequestId"],
where: dateQuery
where: dateQuery,
order: [["searchRequestId", "ASC"]]
});
const excludedRequestsAll = excludedMatches.map(match => {
return match.dataValues.searchRequestId;
});
//Removing duplicate search request id-s for optimization
const excludedRequests = [...new Set(excludedRequestsAll)];
const query = {
subscribed: true,
id: {

View File

@@ -136,9 +136,6 @@ const generateCheckUpEmail = searchRequest => {
? `<div><strong>Kvadratura okućnice: Od ${gardenSizeMin} do ${gardenSizeMax} m2</strong></div>`
: ``;
const allRealEstatesLink = `${APP_URL}/nekretnine/${id}`;
const moreRealEstates = `<div>Kompletan spisak do sada pronađenih nekretnina možete pogledati na <a href="${allRealEstatesLink}">listi nekretnina</a><div>`;
const emailFooter = generateEmailFooter(id);
return `<h3>Zdravo</h3>
@@ -153,8 +150,6 @@ const generateCheckUpEmail = searchRequest => {
<div><strong>Cijena:</strong> ${priceMin} do ${priceMax} KM</div>
</div>
<br/>
${moreRealEstates}
<br/>
${emailFooter}`;
};

View File

@@ -8,8 +8,7 @@ const forceSSL = require("./app/helpers/forceSSL");
const {
APP_PORT,
CRAWLER_INTERVAL,
STOP_CRAWLER,
CHECK_UP_DAYS
STOP_CRAWLER
} = require("./app/config/appConfig");
const routes = require("./app/routes");
const { crawlAll } = require("./app/crawler/crawl");
@@ -50,4 +49,4 @@ const crawl = () => {
setInterval(crawl, CRAWLER_INTERVAL * 1000);
setInterval(checkUpNotify, CHECK_UP_DAYS * 24 * 60 * 60 * 1000);
setInterval(checkUpNotify, 1000 * 60 * 60 * 24);