Changed to send email only to some users.
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const db = require("../../models/index");
|
const db = require("../../models/index");
|
||||||
|
const sequelize = require("sequelize");
|
||||||
|
const Op = sequelize.Op;
|
||||||
const { CHECK_UP_DAYS } = require("../../config/appConfig");
|
const { CHECK_UP_DAYS } = require("../../config/appConfig");
|
||||||
|
|
||||||
const findRealEstatesForSearchRequest = async searchRequestId => {
|
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"],
|
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 = {
|
const query = {
|
||||||
subscribed: true,
|
subscribed: true,
|
||||||
id: {
|
id: {
|
||||||
|
|||||||
@@ -136,9 +136,6 @@ const generateCheckUpEmail = searchRequest => {
|
|||||||
? `<div><strong>Kvadratura okućnice: Od ${gardenSizeMin} do ${gardenSizeMax} m2</strong></div>`
|
? `<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);
|
const emailFooter = generateEmailFooter(id);
|
||||||
|
|
||||||
return `<h3>Zdravo</h3>
|
return `<h3>Zdravo</h3>
|
||||||
@@ -153,8 +150,6 @@ const generateCheckUpEmail = searchRequest => {
|
|||||||
<div><strong>Cijena:</strong> ${priceMin} do ${priceMax} KM</div>
|
<div><strong>Cijena:</strong> ${priceMin} do ${priceMax} KM</div>
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
${moreRealEstates}
|
|
||||||
<br/>
|
|
||||||
${emailFooter}`;
|
${emailFooter}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
5
index.js
5
index.js
@@ -8,8 +8,7 @@ const forceSSL = require("./app/helpers/forceSSL");
|
|||||||
const {
|
const {
|
||||||
APP_PORT,
|
APP_PORT,
|
||||||
CRAWLER_INTERVAL,
|
CRAWLER_INTERVAL,
|
||||||
STOP_CRAWLER,
|
STOP_CRAWLER
|
||||||
CHECK_UP_DAYS
|
|
||||||
} = require("./app/config/appConfig");
|
} = require("./app/config/appConfig");
|
||||||
const routes = require("./app/routes");
|
const routes = require("./app/routes");
|
||||||
const { crawlAll } = require("./app/crawler/crawl");
|
const { crawlAll } = require("./app/crawler/crawl");
|
||||||
@@ -50,4 +49,4 @@ const crawl = () => {
|
|||||||
|
|
||||||
setInterval(crawl, CRAWLER_INTERVAL * 1000);
|
setInterval(crawl, CRAWLER_INTERVAL * 1000);
|
||||||
|
|
||||||
setInterval(checkUpNotify, CHECK_UP_DAYS * 24 * 60 * 60 * 1000);
|
setInterval(checkUpNotify, 1000 * 60 * 60 * 24);
|
||||||
|
|||||||
Reference in New Issue
Block a user