Merge branch 'modify-notification-email-subject' into 'master'
modify notification email subject See merge request saburly/marketalarm/web!41
This commit was merged in pull request #41.
This commit is contained in:
@@ -7,7 +7,7 @@ const generateEmailFooter = searchRequestId => {
|
|||||||
return `<div>Ako želite prestati dobijati obavještenja za ovu pretragu, <a href="${APP_URL}/odjava/${searchRequestId}">odjavite ovdje</a></div>
|
return `<div>Ako želite prestati dobijati obavještenja za ovu pretragu, <a href="${APP_URL}/odjava/${searchRequestId}">odjavite ovdje</a></div>
|
||||||
<div>Ako želite pogledati ili promijeniti uslove za ovu pretragu, <a href="${APP_URL}/pregled/${searchRequestId}">pogledajte ovdje</a></div>
|
<div>Ako želite pogledati ili promijeniti uslove za ovu pretragu, <a href="${APP_URL}/pregled/${searchRequestId}">pogledajte ovdje</a></div>
|
||||||
<br/>
|
<br/>
|
||||||
<strong>Vaš,<br/>Javimi tim</strong>`;
|
<strong>Vaš,<br/>Kivi tim</strong>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateRealEstateLinks = realEstates => {
|
const generateRealEstateLinks = realEstates => {
|
||||||
@@ -82,7 +82,32 @@ const generateNewSearchRequestEmail = (searchRequest, matchingRealEstates) => {
|
|||||||
${emailFooter}`;
|
${emailFooter}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const generateEmailSubject = (numberOfRealEstates, singleRealEstateTitle) => {
|
||||||
|
if (numberOfRealEstates === 1) {
|
||||||
|
return `Kivi: ${singleRealEstateTitle}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const leastSignificantDigit = numberOfRealEstates % 10;
|
||||||
|
const numberWithoutLastDigit = Math.floor(numberOfRealEstates / 10);
|
||||||
|
const secondLeastSignificantDigit = numberWithoutLastDigit % 10;
|
||||||
|
|
||||||
|
if (leastSignificantDigit === 1 && secondLeastSignificantDigit !== 1) {
|
||||||
|
return `Kivi : ${numberOfRealEstates} nova nekretnina`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
leastSignificantDigit >= 2 &&
|
||||||
|
leastSignificantDigit <= 4 &&
|
||||||
|
secondLeastSignificantDigit !== 1
|
||||||
|
) {
|
||||||
|
return `Kivi: ${numberOfRealEstates} nove nekretnine`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `Kivi: ${numberOfRealEstates} novih nekretnina`;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
generateNotificationEmail,
|
generateNotificationEmail,
|
||||||
generateNewSearchRequestEmail
|
generateNewSearchRequestEmail,
|
||||||
|
generateEmailSubject
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ const {
|
|||||||
} = require("../services/searchMatchService");
|
} = require("../services/searchMatchService");
|
||||||
const {
|
const {
|
||||||
generateNotificationEmail,
|
generateNotificationEmail,
|
||||||
generateNewSearchRequestEmail
|
generateNewSearchRequestEmail,
|
||||||
|
generateEmailSubject
|
||||||
} = require("../helpers/emailContentGenerator");
|
} = require("../helpers/emailContentGenerator");
|
||||||
const { sendEmail } = require("../services/emailService");
|
const { sendEmail } = require("../services/emailService");
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ const notifyForNewSearchRequest = async searchRequest => {
|
|||||||
matchingRealEstates
|
matchingRealEstates
|
||||||
);
|
);
|
||||||
const { email } = searchRequest;
|
const { email } = searchRequest;
|
||||||
await sendEmail(email, "Market Alert", emailContent);
|
await sendEmail(email, "Kivi - novi zahtjev za pretragu", emailContent);
|
||||||
};
|
};
|
||||||
|
|
||||||
const notifyMatches = async matches => {
|
const notifyMatches = async matches => {
|
||||||
@@ -36,11 +37,20 @@ const notifyMatches = async matches => {
|
|||||||
const { searchRequest } = matches[id];
|
const { searchRequest } = matches[id];
|
||||||
const { email } = searchRequest;
|
const { email } = searchRequest;
|
||||||
const allMatchingRealEstates = matches[id].realEstates || [];
|
const allMatchingRealEstates = matches[id].realEstates || [];
|
||||||
const emailContent = generateNotificationEmail(allMatchingRealEstates, id);
|
if (allMatchingRealEstates.length > 0) {
|
||||||
|
const emailContent = generateNotificationEmail(
|
||||||
|
allMatchingRealEstates,
|
||||||
|
id
|
||||||
|
);
|
||||||
|
const emailSubject = generateEmailSubject(
|
||||||
|
allMatchingRealEstates.length,
|
||||||
|
allMatchingRealEstates[0].title
|
||||||
|
);
|
||||||
|
|
||||||
const sendEmailPromise = sendEmail(email, "Nove nekretnine", emailContent);
|
const sendEmailPromise = sendEmail(email, emailSubject, emailContent);
|
||||||
asyncSendEmailActions.push(sendEmailPromise);
|
asyncSendEmailActions.push(sendEmailPromise);
|
||||||
sendEmailPromise.catch(err => console.log("[Email Sending Failed]", err));
|
sendEmailPromise.catch(err => console.log("[Email Sending Failed]", err));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(asyncSendEmailActions);
|
await Promise.all(asyncSendEmailActions);
|
||||||
|
|||||||
@@ -4,21 +4,8 @@ const {
|
|||||||
} = require("../app/services/notificationService");
|
} = require("../app/services/notificationService");
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const realEstate1 = await getRealEstateById(53069); //B.Luka, 149.000 KM, 67m2
|
const realEstate1 = await getRealEstateById(83985);
|
||||||
const realEstate2 = await getRealEstateById(53180); //B.Luka, 70.000 KM, 24m2
|
const realEstate2 = await getRealEstateById(83984);
|
||||||
|
|
||||||
const realEstate3 = await getRealEstateById(53067); //Grbavica, 109.500 KM, 51m2
|
notifyForNewRealEstates([realEstate1]);
|
||||||
const realEstate4 = await getRealEstateById(53077); //alipašino, 66.000 KM, 32.58 m2
|
|
||||||
|
|
||||||
const realEstate5 = await getRealEstateById(53080); //Tuzla, - KM, 47,1 m2
|
|
||||||
const realEstate6 = await getRealEstateById(53646); //Tuzla, 73.500 KM, 53m2
|
|
||||||
|
|
||||||
notifyForNewRealEstates([
|
|
||||||
realEstate1,
|
|
||||||
realEstate2,
|
|
||||||
realEstate3,
|
|
||||||
realEstate4,
|
|
||||||
realEstate5,
|
|
||||||
realEstate6
|
|
||||||
]);
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user