add helper to generate email; install html-to-text package
This commit is contained in:
79
app/helpers/emailContentGenerator.js
Normal file
79
app/helpers/emailContentGenerator.js
Normal file
@@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
|
||||
const { MAX_REAL_ESTATES_IN_EMAIL, APP_URL } = require("../config/appConfig");
|
||||
const { AD_CATEGORY } = require("../common/enums");
|
||||
|
||||
const generateEmailFooter = searchRequestId => {
|
||||
return `<div><strong>Ako želite prestati dobijati obavještenja za ovu pretragu, <a href="${APP_URL}/odjava/${searchRequestId}">odjavite ovdje</a></strong></div>
|
||||
<div><strong>Ako želite pogledati ili promijeniti uslove za ovu pretragu, <a href="${APP_URL}/pregled/${searchRequestId}">pogledajte ovdje</a></strong></div>
|
||||
<br/>
|
||||
<h4> Vaš,<br/>Javimi tim</h4>`;
|
||||
};
|
||||
|
||||
const generateNotificationEmail = (realEstates, searchRequestId) => {
|
||||
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}`;
|
||||
|
||||
let realEstateLinks = "";
|
||||
for (const realEstate of realEstatesToShow) {
|
||||
const { id: realEstateId, title } = realEstate;
|
||||
|
||||
realEstateLinks += `<li><a href="${APP_URL}/redirect/${realEstateId}">${title}</a></li><br />`;
|
||||
}
|
||||
|
||||
const moreRealEstates = truncateList
|
||||
? `<div>Kompletan spisak nekretnina možete pegledati na: <a href="${allRealEstatesLink}">Nekretnine</a><div>`
|
||||
: "";
|
||||
|
||||
const emailFooter = generateEmailFooter(searchRequestId);
|
||||
|
||||
return `<h3> Zdravo,
|
||||
Ovo su nekretnine koje ste tražili. </h3>
|
||||
<div>
|
||||
${realEstateLinks}
|
||||
<div/>
|
||||
${moreRealEstates}
|
||||
</div>
|
||||
<br/>
|
||||
${emailFooter}`;
|
||||
};
|
||||
|
||||
const generateNewSearchRequestEmail = 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 emailFooter = generateEmailFooter(id);
|
||||
|
||||
return `<h3> Zdravo<br/>Naručili ste da Vam javimo ako se nekretnina pojavi u oglasima. </h3>
|
||||
<h4> Ovo su uslovi pretrage :</h4>
|
||||
<div>
|
||||
<div><strong>Tip nekretnine: </strong>${realEstateType.title}</div>
|
||||
<div><strong>Lokacija: </strong></div>
|
||||
<div><strong>Kvadratura nekretnine:</strong> Od ${sizeMin} do ${sizeMax} m2</div>
|
||||
${gardenSize}
|
||||
<div><strong>Cijena:</strong> ${priceMin} do ${priceMax} KM</div>
|
||||
</div>
|
||||
<br/>
|
||||
${emailFooter}`;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
generateNotificationEmail,
|
||||
generateNewSearchRequestEmail
|
||||
};
|
||||
Reference in New Issue
Block a user