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
|
||||
};
|
||||
23
package-lock.json
generated
23
package-lock.json
generated
@@ -2077,6 +2077,29 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"he": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
|
||||
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw=="
|
||||
},
|
||||
"html-to-text": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/html-to-text/-/html-to-text-5.1.1.tgz",
|
||||
"integrity": "sha512-Bci6bD/JIfZSvG4s0gW/9mMKwBRoe/1RWLxUME/d6WUSZCdY7T60bssf/jFf7EYXRyqU4P5xdClVqiYU0/ypdA==",
|
||||
"requires": {
|
||||
"he": "^1.2.0",
|
||||
"htmlparser2": "^3.10.1",
|
||||
"lodash": "^4.17.11",
|
||||
"minimist": "^1.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"minimist": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
|
||||
}
|
||||
}
|
||||
},
|
||||
"htmlparser2": {
|
||||
"version": "3.10.1",
|
||||
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.10.1.tgz",
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
"express": "^4.16.4",
|
||||
"express-ejs-layouts": "^2.5.0",
|
||||
"express-layout": "^0.1.0",
|
||||
"html-to-text": "^5.1.1",
|
||||
"moment": "^2.24.0",
|
||||
"moment-timezone": "^0.5.26",
|
||||
"node-fetch": "^2.3.0",
|
||||
|
||||
Reference in New Issue
Block a user