improve email notification copy; add different copy for daily email

This commit is contained in:
Bilal Catic
2019-11-04 14:28:11 +01:00
parent 2be013de1f
commit 4d5571b1d8
2 changed files with 21 additions and 5 deletions

View File

@@ -20,7 +20,11 @@ const generateRealEstateLinks = realEstates => {
return realEstateLinks; return realEstateLinks;
}; };
const generateNotificationEmail = (realEstates, searchRequestId) => { const generateNotificationEmail = (
realEstates,
searchRequestId,
dailyNotification = false
) => {
const truncateList = realEstates.length > MAX_REAL_ESTATES_IN_EMAIL; const truncateList = realEstates.length > MAX_REAL_ESTATES_IN_EMAIL;
const realEstatesToShow = truncateList const realEstatesToShow = truncateList
? realEstates.slice(0, MAX_REAL_ESTATES_IN_EMAIL) ? realEstates.slice(0, MAX_REAL_ESTATES_IN_EMAIL)
@@ -30,9 +34,20 @@ const generateNotificationEmail = (realEstates, searchRequestId) => {
const realEstateLinks = generateRealEstateLinks(realEstatesToShow); const realEstateLinks = generateRealEstateLinks(realEstatesToShow);
const moreRealEstates = `<div>Kompletan spisak nekretnina možete pogledati na <a href="${allRealEstatesLink}">listi nekretnina</a><div>`; const moreRealEstates = `<div>Kompletan spisak nekretnina možete pogledati na <a href="${allRealEstatesLink}">listi nekretnina</a><div>`;
const emailFooter = generateEmailFooter(searchRequestId); 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 `<h3>Zdravo</h3> return `<h3>Zdravo</h3>
<h4>Pronašli smo nekretnine koje odgovaraju Vašoj pretrazi</h4> <h4>${messageBody}</h4>
<div> <div>
${realEstateLinks} ${realEstateLinks}
<div/> <div/>

View File

@@ -30,7 +30,7 @@ const notifyForNewSearchRequest = async searchRequest => {
await sendEmail(email, "Kivi - novi zahtjev za pretragu", emailContent); 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 searchRequestsToNotify = Object.keys(matches);
const asyncSendEmailActions = []; const asyncSendEmailActions = [];
@@ -42,7 +42,8 @@ const notifyMatches = async matches => {
if (allMatchingRealEstates.length > 0) { if (allMatchingRealEstates.length > 0) {
const emailContent = generateNotificationEmail( const emailContent = generateNotificationEmail(
allMatchingRealEstates, allMatchingRealEstates,
id id,
dailyNotification
); );
const emailSubject = generateEmailSubject( const emailSubject = generateEmailSubject(
allMatchingRealEstates.length, allMatchingRealEstates.length,
@@ -105,7 +106,7 @@ const notifyRequestsWithDailyOption = async () => {
searchRequestMatch.save(); searchRequestMatch.save();
} }
await notifyMatches(matches); await notifyMatches(matches, true);
}; };
module.exports = { module.exports = {