diff --git a/app/helpers/emailContentGenerator.js b/app/helpers/emailContentGenerator.js index 861bfb2..2aa9e4b 100644 --- a/app/helpers/emailContentGenerator.js +++ b/app/helpers/emailContentGenerator.js @@ -23,16 +23,19 @@ const generateRealEstateLinks = realEstates => { const generateNotificationEmail = ( realEstates, searchRequestId, + noAllRealEstates, dailyNotification = false ) => { const truncateList = realEstates.length > MAX_REAL_ESTATES_IN_EMAIL; + const realEstatesToShow = truncateList ? realEstates.slice(0, MAX_REAL_ESTATES_IN_EMAIL) : realEstates; const allRealEstatesLink = `${APP_URL}/nekretnine/${searchRequestId}`; + const realEstateLinks = generateRealEstateLinks(realEstatesToShow); - const moreRealEstates = `
Kompletan spisak nekretnina možete pogledati na listi nekretnina
`; + const moreRealEstates = `
Kompletan spisak nekretnina (${noAllRealEstates}) možete pogledati na listi nekretnina
`; const emailFooter = generateEmailFooter(searchRequestId); const asapMessageBody = realEstates.length > 1 @@ -70,6 +73,7 @@ const generateNewSearchRequestEmail = (searchRequest, matchingRealEstates) => { } = searchRequest; const realEstateLinks = generateRealEstateLinks(matchingRealEstates); + const instantRealEstatesText = `
U međuvremenu pogledajte neke od nedavno objavljenih nekretnina koje odgovaraju Vašim uslovima pretrage :
diff --git a/app/services/notificationService.js b/app/services/notificationService.js index 7495e17..7a4a62a 100644 --- a/app/services/notificationService.js +++ b/app/services/notificationService.js @@ -8,7 +8,10 @@ const { generateNewSearchRequestEmail, generateEmailSubject } = require("../helpers/emailContentGenerator"); -const { findNotNotifiedMatches } = require("../helpers/db/searchRequestMatch"); +const { + findNotNotifiedMatches, + findRealEstatesForSearchRequest +} = require("../helpers/db/searchRequestMatch"); const { sendEmail } = require("../services/emailService"); const notifyForNewRealEstates = async newRealEstates => { @@ -39,10 +42,18 @@ const notifyMatches = async (matches, dailyNotification = false) => { const { email, subscribed } = searchRequest; if (notifyNow && subscribed) { const allMatchingRealEstates = matches[id].realEstates || []; + + //Variable allMatchingRealEstates are real estates that are "new" on the market + //the ones that we notify user in this moment, not all that already exists in db + //New variable allRealEstates are all real estates that exists in db for search req + const allRealEstates = await findRealEstatesForSearchRequest(id); + const noAllRealEstates = allRealEstates.length; + if (allMatchingRealEstates.length > 0) { const emailContent = generateNotificationEmail( allMatchingRealEstates, id, + noAllRealEstates, dailyNotification ); const emailSubject = generateEmailSubject(