`;
+
+ const emailFooter = generateEmailFooter(id);
+
+ return `
Zdravo
+
Kivi tim traži nekretnine za Vas i kada to ne vidite.
+
+
Vaša trenutno aktivna pretraga je:
+
+
+
Tip nekretnine: ${realEstateType.title}
+
Kvadratura nekretnine: Od ${sizeMin} do ${sizeMax} m2
+ ${gardenSize}
+
Cijena: ${priceMin} do ${priceMax} KM
+
+
+ ${moreRealEstates}
+
+ ${emailFooter}`;
+};
+
module.exports = {
generateNotificationEmail,
generateNewSearchRequestEmail,
- generateEmailSubject
+ generateEmailSubject,
+ generateCheckUpEmail
};
diff --git a/app/npmScripts/npmCheckUpNotify.js b/app/npmScripts/npmCheckUpNotify.js
new file mode 100644
index 0000000..1becb3f
--- /dev/null
+++ b/app/npmScripts/npmCheckUpNotify.js
@@ -0,0 +1,6 @@
+"use strict";
+const { checkUpNotifyAll } = require("../services/notificationService");
+
+(async () => {
+ await checkUpNotifyAll();
+})();
diff --git a/app/services/notificationService.js b/app/services/notificationService.js
index 7495e17..10a74df 100644
--- a/app/services/notificationService.js
+++ b/app/services/notificationService.js
@@ -6,9 +6,13 @@ const {
const {
generateNotificationEmail,
generateNewSearchRequestEmail,
- generateEmailSubject
+ generateEmailSubject,
+ generateCheckUpEmail
} = require("../helpers/emailContentGenerator");
-const { findNotNotifiedMatches } = require("../helpers/db/searchRequestMatch");
+const {
+ findNotNotifiedMatches,
+ findAllRequestsForCheckUp
+} = require("../helpers/db/searchRequestMatch");
const { sendEmail } = require("../services/emailService");
const notifyForNewRealEstates = async newRealEstates => {
@@ -109,8 +113,26 @@ const notifyRequestsWithDailyOption = async () => {
await notifyMatches(matches, true);
};
+const checkUpNotifyAll = async () => {
+ const searchRequestsForCheckUp = await findAllRequestsForCheckUp();
+
+ const asyncSendEmailActions = [];
+
+ for (const searchRequest of searchRequestsForCheckUp) {
+ const { email } = searchRequest.dataValues;
+ const emailSubject = `Kivi: Mi tražimo nekretnine za vas!`;
+ const emailContent = generateCheckUpEmail(searchRequest.dataValues);
+
+ const sendEmailPromise = sendEmail(email, emailSubject, emailContent);
+ asyncSendEmailActions.push(sendEmailPromise);
+ sendEmailPromise.catch(err => console.log("[Email Sending Failed]", err));
+ }
+ await Promise.all(asyncSendEmailActions);
+};
+
module.exports = {
notifyForNewRealEstates,
notifyForNewSearchRequest,
- notifyRequestsWithDailyOption
+ notifyRequestsWithDailyOption,
+ checkUpNotifyAll
};
diff --git a/package.json b/package.json
index 75a7cc4..b4ce4a8 100644
--- a/package.json
+++ b/package.json
@@ -13,6 +13,7 @@
"docker-stop": "docker stop pg_marketalerts",
"crawl": "cd app/crawler && node npmCrawl.js",
"daily-notify": "cd app/npmScripts && node npmDailyNotify.js",
+ "checkup-notify": "cd app/npmScripts && node npmCheckUpNotify.js",
"test-search": "cd test && node searchTest.js",
"test-olx-scraper": "cd test && node olxScrapeTest.js",
"test-rental-scraper": "cd test && node rentalScrapeTest.js"