Added check up email that everything works.
This commit is contained in:
@@ -40,6 +40,16 @@ const findNotNotifiedMatches = async () => {
|
|||||||
|
|
||||||
return matchingRecords;
|
return matchingRecords;
|
||||||
};
|
};
|
||||||
|
const findAllRequestsForCheckUp = async () => {
|
||||||
|
const query = {
|
||||||
|
subscribed: true
|
||||||
|
};
|
||||||
|
const allRequestsForCheckUp = await db.SearchRequest.findAll({
|
||||||
|
where: query
|
||||||
|
});
|
||||||
|
|
||||||
|
return allRequestsForCheckUp;
|
||||||
|
};
|
||||||
|
|
||||||
const addMatches = async matchingRecords => {
|
const addMatches = async matchingRecords => {
|
||||||
return await db.SearchRequestMatch.bulkCreate(matchingRecords, {
|
return await db.SearchRequestMatch.bulkCreate(matchingRecords, {
|
||||||
@@ -50,5 +60,6 @@ const addMatches = async matchingRecords => {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
findRealEstatesForSearchRequest,
|
findRealEstatesForSearchRequest,
|
||||||
addMatches,
|
addMatches,
|
||||||
findNotNotifiedMatches
|
findNotNotifiedMatches,
|
||||||
|
findAllRequestsForCheckUp
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -120,8 +120,47 @@ const generateEmailSubject = (numberOfRealEstates, singleRealEstateTitle) => {
|
|||||||
return `Kivi: ${numberOfRealEstates} novih nekretnina`;
|
return `Kivi: ${numberOfRealEstates} novih nekretnina`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const generateCheckUpEmail = searchRequest => {
|
||||||
|
const realEstateType = AD_CATEGORY[searchRequest.realEstateType];
|
||||||
|
const {
|
||||||
|
id,
|
||||||
|
gardenSizeMin,
|
||||||
|
gardenSizeMax,
|
||||||
|
sizeMin,
|
||||||
|
sizeMax,
|
||||||
|
priceMin,
|
||||||
|
priceMax
|
||||||
|
} = searchRequest;
|
||||||
|
|
||||||
|
const gardenSize = realEstateType.hasGardenSize
|
||||||
|
? `<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>
|
||||||
|
<div><strong>Kivi tim traži nekretnine za Vas i kada to ne vidite.</strong></div>
|
||||||
|
<br />
|
||||||
|
<div>Vaša trenutno aktivna pretraga je:</div>
|
||||||
|
<br/>
|
||||||
|
<div>
|
||||||
|
<div><strong>Tip nekretnine: </strong>${realEstateType.title}</div>
|
||||||
|
<div><strong>Kvadratura nekretnine:</strong> Od ${sizeMin} do ${sizeMax} m2</div>
|
||||||
|
${gardenSize}
|
||||||
|
<div><strong>Cijena:</strong> ${priceMin} do ${priceMax} KM</div>
|
||||||
|
</div>
|
||||||
|
<br/>
|
||||||
|
${moreRealEstates}
|
||||||
|
<br/>
|
||||||
|
${emailFooter}`;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
generateNotificationEmail,
|
generateNotificationEmail,
|
||||||
generateNewSearchRequestEmail,
|
generateNewSearchRequestEmail,
|
||||||
generateEmailSubject
|
generateEmailSubject,
|
||||||
|
generateCheckUpEmail
|
||||||
};
|
};
|
||||||
|
|||||||
6
app/npmScripts/npmCheckUpNotify.js
Normal file
6
app/npmScripts/npmCheckUpNotify.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
"use strict";
|
||||||
|
const { checkUpNotifyAll } = require("../services/notificationService");
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
await checkUpNotifyAll();
|
||||||
|
})();
|
||||||
@@ -6,9 +6,13 @@ const {
|
|||||||
const {
|
const {
|
||||||
generateNotificationEmail,
|
generateNotificationEmail,
|
||||||
generateNewSearchRequestEmail,
|
generateNewSearchRequestEmail,
|
||||||
generateEmailSubject
|
generateEmailSubject,
|
||||||
|
generateCheckUpEmail
|
||||||
} = require("../helpers/emailContentGenerator");
|
} = require("../helpers/emailContentGenerator");
|
||||||
const { findNotNotifiedMatches } = require("../helpers/db/searchRequestMatch");
|
const {
|
||||||
|
findNotNotifiedMatches,
|
||||||
|
findAllRequestsForCheckUp
|
||||||
|
} = require("../helpers/db/searchRequestMatch");
|
||||||
const { sendEmail } = require("../services/emailService");
|
const { sendEmail } = require("../services/emailService");
|
||||||
|
|
||||||
const notifyForNewRealEstates = async newRealEstates => {
|
const notifyForNewRealEstates = async newRealEstates => {
|
||||||
@@ -109,8 +113,26 @@ const notifyRequestsWithDailyOption = async () => {
|
|||||||
await notifyMatches(matches, true);
|
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 = {
|
module.exports = {
|
||||||
notifyForNewRealEstates,
|
notifyForNewRealEstates,
|
||||||
notifyForNewSearchRequest,
|
notifyForNewSearchRequest,
|
||||||
notifyRequestsWithDailyOption
|
notifyRequestsWithDailyOption,
|
||||||
|
checkUpNotifyAll
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
"docker-stop": "docker stop pg_marketalerts",
|
"docker-stop": "docker stop pg_marketalerts",
|
||||||
"crawl": "cd app/crawler && node npmCrawl.js",
|
"crawl": "cd app/crawler && node npmCrawl.js",
|
||||||
"daily-notify": "cd app/npmScripts && node npmDailyNotify.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-search": "cd test && node searchTest.js",
|
||||||
"test-olx-scraper": "cd test && node olxScrapeTest.js",
|
"test-olx-scraper": "cd test && node olxScrapeTest.js",
|
||||||
"test-rental-scraper": "cd test && node rentalScrapeTest.js"
|
"test-rental-scraper": "cd test && node rentalScrapeTest.js"
|
||||||
|
|||||||
Reference in New Issue
Block a user