From 4d5571b1d85df89289eead229bc8b387f4d95bae Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Mon, 4 Nov 2019 14:28:11 +0100 Subject: [PATCH] improve email notification copy; add different copy for daily email --- app/helpers/emailContentGenerator.js | 19 +++++++++++++++++-- app/services/notificationService.js | 7 ++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/helpers/emailContentGenerator.js b/app/helpers/emailContentGenerator.js index 549883e..861bfb2 100644 --- a/app/helpers/emailContentGenerator.js +++ b/app/helpers/emailContentGenerator.js @@ -20,7 +20,11 @@ const generateRealEstateLinks = realEstates => { return realEstateLinks; }; -const generateNotificationEmail = (realEstates, searchRequestId) => { +const generateNotificationEmail = ( + realEstates, + searchRequestId, + dailyNotification = false +) => { const truncateList = realEstates.length > MAX_REAL_ESTATES_IN_EMAIL; const realEstatesToShow = truncateList ? realEstates.slice(0, MAX_REAL_ESTATES_IN_EMAIL) @@ -30,9 +34,20 @@ const generateNotificationEmail = (realEstates, searchRequestId) => { const realEstateLinks = generateRealEstateLinks(realEstatesToShow); const moreRealEstates = `
Kompletan spisak nekretnina možete pogledati na listi nekretnina
`; const emailFooter = generateEmailFooter(searchRequestId); + const asapMessageBody = + realEstates.length > 1 + ? "Pronašli smo nekretnine koje odgovaraju Vašoj pretrazi" + : "Pronašli smo nekretninu koja odgovara Vašoj pretrazi"; + + const dailyMessageBody = + realEstates.length > 1 + ? "U posljednja 24h objavljene su sljedeće nekretnine koje odgovaraju uslovima Vaše pretrage" + : "U posljednja 24h objavljena je sljedeća nekretnina koja odgovara uslovima Vaše pretrage"; + + const messageBody = dailyNotification ? dailyMessageBody : asapMessageBody; return `

Zdravo

-

Pronašli smo nekretnine koje odgovaraju Vašoj pretrazi

+

${messageBody}

${realEstateLinks}
diff --git a/app/services/notificationService.js b/app/services/notificationService.js index 8a90a4c..194d3f6 100644 --- a/app/services/notificationService.js +++ b/app/services/notificationService.js @@ -30,7 +30,7 @@ const notifyForNewSearchRequest = async searchRequest => { await sendEmail(email, "Kivi - novi zahtjev za pretragu", emailContent); }; -const notifyMatches = async matches => { +const notifyMatches = async (matches, dailyNotification = false) => { const searchRequestsToNotify = Object.keys(matches); const asyncSendEmailActions = []; @@ -42,7 +42,8 @@ const notifyMatches = async matches => { if (allMatchingRealEstates.length > 0) { const emailContent = generateNotificationEmail( allMatchingRealEstates, - id + id, + dailyNotification ); const emailSubject = generateEmailSubject( allMatchingRealEstates.length, @@ -105,7 +106,7 @@ const notifyRequestsWithDailyOption = async () => { searchRequestMatch.save(); } - await notifyMatches(matches); + await notifyMatches(matches, true); }; module.exports = {