79 lines
2.5 KiB
JavaScript
79 lines
2.5 KiB
JavaScript
"use strict";
|
|
|
|
const { MAX_REAL_ESTATES_IN_EMAIL, APP_URL } = require("../config/appConfig");
|
|
const { AD_CATEGORY } = require("../common/enums");
|
|
|
|
const generateEmailFooter = searchRequestId => {
|
|
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>
|
|
<br/>
|
|
<strong>Vaš,<br/>Javimi tim</strong>`;
|
|
};
|
|
|
|
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 = `<div>Kompletan spisak nekretnina možete pegledati na <a href="${allRealEstatesLink}">listi nekretnina</a><div>`;
|
|
|
|
const emailFooter = generateEmailFooter(searchRequestId);
|
|
|
|
return `<h3>Zdravo</h3>
|
|
<h4>Pronašli smo nekretnine koje odgovaraju Vašoj pretrazi</h4>
|
|
<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</h3>
|
|
<div>Naručili ste da Vam javimo ako se nekretnina sa navedenim uslovima pojavi u oglasima:</div>
|
|
<br/>
|
|
<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
|
|
};
|