Email links now point to our URL and then redirect to the original property URL, ran prettier on the affected files
This commit is contained in:
16
app/controllers/redirect.js
Normal file
16
app/controllers/redirect.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const { getMarketAlertById } = require("../helpers/db/dbHelper");
|
||||
|
||||
const redirect = async (req, res) => {
|
||||
const id = req.params["id"];
|
||||
const marketAlert = await getMarketAlertById(id);
|
||||
if (marketAlert) {
|
||||
res.redirect(marketAlert.url);
|
||||
} else {
|
||||
res.send("Not found");
|
||||
res.end();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
redirect
|
||||
};
|
||||
@@ -1,32 +1,29 @@
|
||||
|
||||
const dotenv = require('dotenv').config();
|
||||
const { getRealEstateTypeEnum } = require('./enums');
|
||||
const { getRegionName, getMunicipalityName } = require('./codes');
|
||||
const { allRERequestByUiid } = require('./db/dbHelper');
|
||||
var AWS = require('aws-sdk');
|
||||
const TEMPLATE_NAME = "MarketAlertTemplate"
|
||||
const dotenv = require("dotenv").config();
|
||||
const { getRealEstateTypeEnum } = require("./enums");
|
||||
const { getRegionName, getMunicipalityName } = require("./codes");
|
||||
const { allRERequestByUiid } = require("./db/dbHelper");
|
||||
var AWS = require("aws-sdk");
|
||||
const TEMPLATE_NAME = "MarketAlertTemplate";
|
||||
|
||||
AWS.config.update({
|
||||
region: process.env.AMAZON_REGION,
|
||||
credentials:
|
||||
{
|
||||
credentials: {
|
||||
accessKeyId: process.env.AMAZON_ACCES_KEY_ID,
|
||||
secretAccessKey: process.env.AMAZON_SECRET_ACCESS_KEY
|
||||
}
|
||||
});
|
||||
|
||||
const sendTemplatedEmail = async (email, request) => {
|
||||
|
||||
const params = {
|
||||
Destination: { /* required */
|
||||
CcAddresses: [
|
||||
],
|
||||
ToAddresses: [
|
||||
email
|
||||
]
|
||||
Destination: {
|
||||
/* required */
|
||||
CcAddresses: [],
|
||||
ToAddresses: [email]
|
||||
},
|
||||
Message: { /* required */
|
||||
Body: { /* required */
|
||||
Message: {
|
||||
/* required */
|
||||
Body: {
|
||||
/* required */
|
||||
Html: {
|
||||
Charset: "UTF-8",
|
||||
Data: getGreetingsEmailHTML(request)
|
||||
@@ -37,76 +34,124 @@ const sendTemplatedEmail = async (email, request) => {
|
||||
}
|
||||
},
|
||||
Subject: {
|
||||
Charset: 'UTF-8',
|
||||
Data: `Javimi Potvrda: ${getSubject(request.realEstateType, request.region, request.municipality)}`
|
||||
Charset: "UTF-8",
|
||||
Data: `Javimi Potvrda: ${getSubject(
|
||||
request.realEstateType,
|
||||
request.region,
|
||||
request.municipality
|
||||
)}`
|
||||
}
|
||||
},
|
||||
Source: process.env.SOURCE_EMAIL, /* required */
|
||||
ReplyToAddresses: [
|
||||
process.env.SOURCE_EMAIL,
|
||||
],
|
||||
Source: process.env.SOURCE_EMAIL /* required */,
|
||||
ReplyToAddresses: [process.env.SOURCE_EMAIL]
|
||||
};
|
||||
|
||||
const sendEmailPromise = new AWS.SES({ apiVersion: '2010-12-01' }).sendEmail(params).promise();
|
||||
const sendEmailPromise = new AWS.SES({ apiVersion: "2010-12-01" })
|
||||
.sendEmail(params)
|
||||
.promise();
|
||||
await sendEmailPromise;
|
||||
}
|
||||
};
|
||||
|
||||
const getGreetingsEmailHTML = (realestateRequest) => {
|
||||
const realEstateType = getRealEstateTypeEnum(realestateRequest.realEstateType);
|
||||
const gardenSize = realEstateType.hasGardenSize ? `<div><strong>Kvadratura okućnice: Od ${realestateRequest.gardenSizeMin} do ${realestateRequest.gardenSizeMax} m2 </strong></div>` : ``
|
||||
const getGreetingsEmailHTML = realestateRequest => {
|
||||
const realEstateType = getRealEstateTypeEnum(
|
||||
realestateRequest.realEstateType
|
||||
);
|
||||
const gardenSize = realEstateType.hasGardenSize
|
||||
? `<div><strong>Kvadratura okućnice: Od ${
|
||||
realestateRequest.gardenSizeMin
|
||||
} do ${realestateRequest.gardenSizeMax} m2 </strong></div>`
|
||||
: ``;
|
||||
|
||||
return `<h1> Zdravo,
|
||||
Naručio/la si da ti javimo ako se nekretnina pojavi u oglasima. </h1>
|
||||
<h2> Ovo je tražena nekretnina: </h2>
|
||||
<div>
|
||||
<div> <strong>Tip nekretnine: ${realEstateType.title} </strong></div>
|
||||
<div><strong>Područje: ${getRegionName(realestateRequest.region)} </strong></div>
|
||||
<div><strong>Mjesto: ${getMunicipalityName(realestateRequest.region, realestateRequest.municipality)} </strong></div>
|
||||
<div><strong>Kvadratura nekretnine: Od ${realestateRequest.sizeMin} do ${realestateRequest.sizeMax} m2 </strong></div>
|
||||
<div><strong>Područje: ${getRegionName(
|
||||
realestateRequest.region
|
||||
)} </strong></div>
|
||||
<div><strong>Mjesto: ${getMunicipalityName(
|
||||
realestateRequest.region,
|
||||
realestateRequest.municipality
|
||||
)} </strong></div>
|
||||
<div><strong>Kvadratura nekretnine: Od ${realestateRequest.sizeMin} do ${
|
||||
realestateRequest.sizeMax
|
||||
} m2 </strong></div>
|
||||
${gardenSize}
|
||||
<div><strong>Cijena: ${realestateRequest.priceMin} do ${realestateRequest.priceMax} KM </strong></div>
|
||||
<div><strong>Cijena: ${realestateRequest.priceMin} do ${
|
||||
realestateRequest.priceMax
|
||||
} KM </strong></div>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
</div>
|
||||
<div><strong> Ako želis prestati dobijati obavještenja za ovu pretragu klikni ${process.env.APP_URL}/odjava/${realestateRequest.uniqueId} </strong></div>
|
||||
<div><strong>Ako želiš promijeniti uslove pretrage klikni ${process.env.APP_URL}/pregled/${realestateRequest.uniqueId} </strong></div>
|
||||
<div><strong> Ako želis prestati dobijati obavještenja za ovu pretragu klikni ${
|
||||
process.env.APP_URL
|
||||
}/odjava/${realestateRequest.uniqueId} </strong></div>
|
||||
<div><strong>Ako želiš promijeniti uslove pretrage klikni ${
|
||||
process.env.APP_URL
|
||||
}/pregled/${realestateRequest.uniqueId} </strong></div>
|
||||
<h4> Tvoj,
|
||||
Javimi tim.
|
||||
</h4>`
|
||||
</h4>`;
|
||||
};
|
||||
|
||||
}
|
||||
const getGreetingsEmaiTextVersion = realestateRequest => {
|
||||
const realEstateType = getRealEstateTypeEnum(
|
||||
realestateRequest.realEstateType
|
||||
);
|
||||
const gardenSize = realEstateType.hasGardenSize
|
||||
? "Kvadratura okućnice od " +
|
||||
realestateRequest.gardenSizeMin +
|
||||
" do " +
|
||||
realestateRequest.gardenSizeMax
|
||||
: "";
|
||||
|
||||
const getGreetingsEmaiTextVersion = (realestateRequest) => {
|
||||
const realEstateType = getRealEstateTypeEnum(realestateRequest.realEstateType);
|
||||
const gardenSize = realEstateType.hasGardenSize ? "Kvadratura okućnice od " + realestateRequest.gardenSizeMin + " do " + realestateRequest.gardenSizeMax : ""
|
||||
|
||||
const text = "Zdravo, \n Naručio/la si da ti javimo ako se nekretnina pojavi u oglasima \n Ovo je tražena nekretnina: \n , Tip nekretnine: "
|
||||
+ realestateRequest.realEstateType + "\n Područje" + getRegionName(realestateRequest.region) + "\n Mjesto " + getMunicipalityName(realestateRequest.region, realestateRequest.municipality)
|
||||
+ "\n Kvadratura nekretnine Od " + realestateRequest.sizeMin + " do " + realestateRequest.sizeMaX +
|
||||
+ gardenSize
|
||||
"\n Cijena od " + realestateRequest.priceMin + " do " + realestateRequest.priceMax +
|
||||
"\n Ako želis prestati dobijati obavještenja za ovu pretragu klikni" + process.env.APP_URL + "/odjava/" + realestateRequest.uniqueId +
|
||||
"\n Ako želiš promijeniti uslove pretrage klikni " + process.env.APP_URL + "/odpregled/" + realestateRequest.uniqueId +
|
||||
"\n Tvoj,\n Javimi tim"
|
||||
const text =
|
||||
"Zdravo, \n Naručio/la si da ti javimo ako se nekretnina pojavi u oglasima \n Ovo je tražena nekretnina: \n , Tip nekretnine: " +
|
||||
realestateRequest.realEstateType +
|
||||
"\n Područje" +
|
||||
getRegionName(realestateRequest.region) +
|
||||
"\n Mjesto " +
|
||||
getMunicipalityName(
|
||||
realestateRequest.region,
|
||||
realestateRequest.municipality
|
||||
) +
|
||||
"\n Kvadratura nekretnine Od " +
|
||||
realestateRequest.sizeMin +
|
||||
" do " +
|
||||
realestateRequest.sizeMaX +
|
||||
+gardenSize;
|
||||
"\n Cijena od " +
|
||||
realestateRequest.priceMin +
|
||||
" do " +
|
||||
realestateRequest.priceMax +
|
||||
"\n Ako želis prestati dobijati obavještenja za ovu pretragu klikni" +
|
||||
process.env.APP_URL +
|
||||
"/odjava/" +
|
||||
realestateRequest.uniqueId +
|
||||
"\n Ako želiš promijeniti uslove pretrage klikni " +
|
||||
process.env.APP_URL +
|
||||
"/odpregled/" +
|
||||
realestateRequest.uniqueId +
|
||||
"\n Tvoj,\n Javimi tim";
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
const sendBulkEmail = async (marketAlerts) => {
|
||||
};
|
||||
|
||||
const sendBulkEmail = async marketAlerts => {
|
||||
try {
|
||||
|
||||
destinations = []
|
||||
destinations = [];
|
||||
groupedRERequests = [];
|
||||
|
||||
|
||||
const RERequestUuidsMaped = marketAlerts.map(marketAlert => marketAlert.request);
|
||||
const RERequestUuidsMaped = marketAlerts.map(
|
||||
marketAlert => marketAlert.request
|
||||
);
|
||||
|
||||
const RERequestUuidsArray = Array.from(new Set(RERequestUuidsMaped));
|
||||
|
||||
const RERequestUuids = RERequestUuidsArray.map(marketAlert => {
|
||||
return { uniqueId: marketAlert }
|
||||
return { uniqueId: marketAlert };
|
||||
});
|
||||
|
||||
const RERequests = await allRERequestByUiid(RERequestUuids);
|
||||
@@ -114,25 +159,24 @@ const sendBulkEmail = async (marketAlerts) => {
|
||||
|
||||
RERequests.forEach(RERequest => {
|
||||
var formatedRequest = {};
|
||||
formatedRequest[RERequest.uniqueId] =
|
||||
requestDataValues[RERequest.uniqueId] = {
|
||||
realEstateType: RERequest.realEstateType,
|
||||
region: RERequest.region,
|
||||
municipality: RERequest.municipality,
|
||||
requestUrl : `${process.env.APP_URL}/nekretnine/${RERequest.uniqueId}`
|
||||
};
|
||||
formatedRequest[RERequest.uniqueId] = requestDataValues[
|
||||
RERequest.uniqueId
|
||||
] = {
|
||||
realEstateType: RERequest.realEstateType,
|
||||
region: RERequest.region,
|
||||
municipality: RERequest.municipality,
|
||||
requestUrl: `${process.env.APP_URL}/nekretnine/${RERequest.uniqueId}`
|
||||
};
|
||||
});
|
||||
|
||||
marketAlerts.forEach(marketAlert => {
|
||||
|
||||
const requestObject = {
|
||||
email: marketAlert.email,
|
||||
realEstateType: requestDataValues[marketAlert.request].realEstateType,
|
||||
municipality: requestDataValues[marketAlert.request].municipality,
|
||||
region: requestDataValues[marketAlert.request].region,
|
||||
requestUrl: requestDataValues[marketAlert.request].requestUrl
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
if (!groupedRERequests[marketAlert.request]) {
|
||||
groupedRERequests[marketAlert.request] = {
|
||||
@@ -144,65 +188,66 @@ const sendBulkEmail = async (marketAlerts) => {
|
||||
groupedRERequests[marketAlert.request].marketAlertArray.push({
|
||||
url: marketAlert.url,
|
||||
title: marketAlert.title,
|
||||
id: marketAlert.id
|
||||
});
|
||||
});
|
||||
for (request in groupedRERequests) {
|
||||
|
||||
const marketAlert = groupedRERequests[request];
|
||||
let extractedData = toAWSArray(marketAlert.marketAlertArray);
|
||||
const realEstateType = getRealEstateTypeEnum(marketAlert.requestObject.realEstateType).title;
|
||||
const realEstateType = getRealEstateTypeEnum(
|
||||
marketAlert.requestObject.realEstateType
|
||||
).title;
|
||||
const region = getRegionName(marketAlert.requestObject.region);
|
||||
const municipality = getMunicipalityName(marketAlert.requestObject.region, marketAlert.requestObject.municipality);
|
||||
const requestUrl = marketAlert.requestObject.requestUrl
|
||||
const municipality = getMunicipalityName(
|
||||
marketAlert.requestObject.region,
|
||||
marketAlert.requestObject.municipality
|
||||
);
|
||||
const requestUrl = marketAlert.requestObject.requestUrl;
|
||||
|
||||
let repData = `{ "marketAlertUrl":[${extractedData}], "realestateType":"${realEstateType}", "region":"${region}", "municipality":"${municipality}", "requestUrl":"${requestUrl}" }`
|
||||
let repData = `{ "marketAlertUrl":[${extractedData}], "realestateType":"${realEstateType}", "region":"${region}", "municipality":"${municipality}", "requestUrl":"${requestUrl}" }`;
|
||||
|
||||
destinations.push({
|
||||
Destination: {
|
||||
ToAddresses: [
|
||||
marketAlert.requestObject.email
|
||||
]
|
||||
ToAddresses: [marketAlert.requestObject.email]
|
||||
},
|
||||
ReplacementTemplateData: repData
|
||||
})
|
||||
|
||||
});
|
||||
}
|
||||
console.log("AWS EMAIL : Bulk email replacement data:");
|
||||
console.log(destinations);
|
||||
|
||||
var params = {
|
||||
Destinations:
|
||||
destinations,
|
||||
Source: process.env.SOURCE_EMAIL, /* required */
|
||||
Template: TEMPLATE_NAME, /* required */
|
||||
DefaultTemplateData: '{ \"REPLACEMENT_TAG_NAME\":\"REPLACEMENT_VALUE\" }',
|
||||
ReplyToAddresses: [
|
||||
process.env.SOURCE_EMAIL,
|
||||
]
|
||||
Destinations: destinations,
|
||||
Source: process.env.SOURCE_EMAIL /* required */,
|
||||
Template: TEMPLATE_NAME /* required */,
|
||||
DefaultTemplateData: '{ "REPLACEMENT_TAG_NAME":"REPLACEMENT_VALUE" }',
|
||||
ReplyToAddresses: [process.env.SOURCE_EMAIL]
|
||||
};
|
||||
|
||||
// Create the promise and SES service object
|
||||
const sendPromise = new AWS.SES({ apiVersion: '2010-12-01' }).sendBulkTemplatedEmail(params).promise();
|
||||
const sendPromise = new AWS.SES({ apiVersion: "2010-12-01" })
|
||||
.sendBulkTemplatedEmail(params)
|
||||
.promise();
|
||||
const awsResult = await sendPromise;
|
||||
console.log("AWS SES bulk email response");
|
||||
console.log(awsResult);
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.log("Could not send bulk email", e)
|
||||
console.log("Could not send bulk email", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const toAWSArray = (urlArray) => {
|
||||
|
||||
let arrayString = ""
|
||||
const redirectUrl = marketAlertId =>
|
||||
`${process.env.APP_URL}/redirect/${marketAlertId}`;
|
||||
const toAWSArray = urlArray => {
|
||||
let arrayString = "";
|
||||
urlArray.forEach(element => {
|
||||
const formatetdTitle = element.title.replace(/"/g, "");
|
||||
arrayString = arrayString + `{"url":"${element.url.trim()}" , "title":"${formatetdTitle}"},`
|
||||
arrayString =
|
||||
arrayString +
|
||||
`{"url":"${redirectUrl(element.id)}" , "title":"${formatetdTitle}"},`;
|
||||
});
|
||||
return arrayString.slice(0, -1);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
const getNotificationEmailHtml = () => {
|
||||
return `<h2> Zdravo,
|
||||
@@ -212,36 +257,40 @@ const getNotificationEmailHtml = () => {
|
||||
<div>{{#each marketAlertUrl}}<li><a href="{{url}}">{{title}}</a></li><br />{{/each}}<div/>
|
||||
<div/>
|
||||
<div>Kompletan spisak nekretnina možete pegledati ovdije: <a href="{{requestUrl}}">Nekretnine</a> <div>
|
||||
</div>`
|
||||
}
|
||||
</div>`;
|
||||
};
|
||||
|
||||
const getNotificationEmailText = () => {
|
||||
return ` Zdravo,
|
||||
Pronašli smo nekretninu koju ste tražili. Ovo su tražene nekretnine: {{#each marketAlertUrl}} {{url}} {{title}} {{/each}} , Kompletan spisan nekretnina mozete pegledati ovdije: {{requestUrl}}`
|
||||
}
|
||||
Pronašli smo nekretninu koju ste tražili. Ovo su tražene nekretnine: {{#each marketAlertUrl}} {{url}} {{title}} {{/each}} , Kompletan spisan nekretnina mozete pegledati ovdije: {{requestUrl}}`;
|
||||
};
|
||||
|
||||
const createMarketAlertEmailTemplate = async () => {
|
||||
const marketAlertTemplate = {
|
||||
Template: {
|
||||
TemplateName: TEMPLATE_NAME,
|
||||
SubjectPart: "Javi mi obavijest: {{realestateType}}, {{region}}, {{municipality}}",
|
||||
SubjectPart:
|
||||
"Javi mi obavijest: {{realestateType}}, {{region}}, {{municipality}}",
|
||||
TextPart: getNotificationEmailText(),
|
||||
HtmlPart: getNotificationEmailHtml()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const templatePromise = new AWS.SES({ apiVersion: '2010-12-01' }).updateTemplate(marketAlertTemplate).promise();
|
||||
await templatePromise
|
||||
|
||||
const templatePromise = new AWS.SES({ apiVersion: "2010-12-01" })
|
||||
.updateTemplate(marketAlertTemplate)
|
||||
.promise();
|
||||
await templatePromise;
|
||||
} catch (e) {
|
||||
console.log("Could not create MarketAlertEmailTemplate", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const getSubject = (realEstateType, region, municipality) => {
|
||||
return `${getRealEstateTypeEnum(realEstateType).title} ${getRegionName(region)}, ${getMunicipalityName(region, municipality)}`
|
||||
}
|
||||
return `${getRealEstateTypeEnum(realEstateType).title} ${getRegionName(
|
||||
region
|
||||
)}, ${getMunicipalityName(region, municipality)}`;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
sendTemplatedEmail,
|
||||
|
||||
@@ -1,90 +1,106 @@
|
||||
const db = require('../../models/index');
|
||||
const db = require("../../models/index");
|
||||
|
||||
/**
|
||||
* Find all subscribed RealEstateRequests
|
||||
* Find all subscribed RealEstateRequests
|
||||
*/
|
||||
const allRERequest = async () => {
|
||||
return await db.RealEstateRequest.findAll({
|
||||
where: {
|
||||
subscribed: true
|
||||
}
|
||||
});
|
||||
}
|
||||
return await db.RealEstateRequest.findAll({
|
||||
where: {
|
||||
subscribed: true
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Find all subscribed RealEstateRequests by UUID
|
||||
*/
|
||||
const allRERequestByUiid = async (requestArray) => {
|
||||
|
||||
const allRERequestByUiid = async requestArray => {
|
||||
const Op = db.Sequelize.Op;
|
||||
return await db.RealEstateRequest.findAll({
|
||||
where: {
|
||||
subscribed: true,
|
||||
[Op.or]: requestArray
|
||||
}
|
||||
});
|
||||
}
|
||||
where: {
|
||||
subscribed: true,
|
||||
[Op.or]: requestArray
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Find all , or all depending on notified bolean marketalerts, that the hasLocation is true, and order them by email
|
||||
*
|
||||
*
|
||||
* @param fechAll bolean
|
||||
* @param notified bolean
|
||||
*
|
||||
*
|
||||
* @returns array of MarketAlerts
|
||||
*/
|
||||
const allMarketAlerts = async (fetchAll, notified) => {
|
||||
|
||||
let queryObject = {
|
||||
order: [
|
||||
['email', 'DESC'],
|
||||
]
|
||||
}
|
||||
|
||||
if (!fetchAll){
|
||||
queryObject.where = {
|
||||
notified: notified,
|
||||
hasLocation: true
|
||||
}
|
||||
}
|
||||
|
||||
return await db.MarketAlert.findAll(queryObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all , MarketAlerts depending on request
|
||||
*
|
||||
* @param request string
|
||||
*
|
||||
* @returns array of MarketAlerts
|
||||
*/
|
||||
const allMarketAlertsByRequest = async (request) => {
|
||||
|
||||
let queryObject = {
|
||||
where : {
|
||||
request: request
|
||||
}
|
||||
order: [["email", "DESC"]]
|
||||
};
|
||||
|
||||
if (!fetchAll) {
|
||||
queryObject.where = {
|
||||
notified: notified,
|
||||
hasLocation: true
|
||||
};
|
||||
}
|
||||
|
||||
return await db.MarketAlert.findAll(queryObject);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Find all unnotified marketalerts
|
||||
* Find all , MarketAlerts depending on request
|
||||
*
|
||||
* @param request string
|
||||
*
|
||||
* @returns array of MarketAlerts
|
||||
*/
|
||||
const allMarketAlertsByRequest = async request => {
|
||||
let queryObject = {
|
||||
where: {
|
||||
request: request
|
||||
}
|
||||
};
|
||||
|
||||
return await db.MarketAlert.findAll(queryObject);
|
||||
};
|
||||
|
||||
/**
|
||||
* Find MarketAlerts by id
|
||||
*
|
||||
* @param id number
|
||||
*
|
||||
* @returns single MarketAlert
|
||||
*/
|
||||
const getMarketAlertById = async id => {
|
||||
let queryObject = {
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
};
|
||||
|
||||
return await db.MarketAlert.findOne(queryObject);
|
||||
};
|
||||
|
||||
/**
|
||||
* Find all unnotified marketalerts
|
||||
* @param latLng array
|
||||
* @param email string
|
||||
*
|
||||
*
|
||||
* @returns array of MarketAlerts
|
||||
*/
|
||||
const findPointInsideBoundingBox = async (latLng, email, uniqueId) => {
|
||||
return await db.sequelize.query(`SELECT * FROM "RealEstateRequests" WHERE email = '${email}' AND "uniqueId" = '${uniqueId}' AND subscribed = true AND ST_Contains("RealEstateRequests".bounding_box, ST_GEOMFROMTEXT('POINT (${latLng[0]} ${latLng[1]})'))`);
|
||||
}
|
||||
return await db.sequelize.query(
|
||||
`SELECT * FROM "RealEstateRequests" WHERE email = '${email}' AND "uniqueId" = '${uniqueId}' AND subscribed = true AND ST_Contains("RealEstateRequests".bounding_box, ST_GEOMFROMTEXT('POINT (${
|
||||
latLng[0]
|
||||
} ${latLng[1]})'))`
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
allRERequest,
|
||||
allMarketAlerts,
|
||||
allRERequestByUiid,
|
||||
findPointInsideBoundingBox,
|
||||
allMarketAlertsByRequest
|
||||
allMarketAlertsByRequest,
|
||||
getMarketAlertById
|
||||
};
|
||||
|
||||
156
index.js
156
index.js
@@ -1,19 +1,38 @@
|
||||
const welcome = require('./app/controllers/welcome').getWelcome;
|
||||
const { getRealEstateTypes, postRealEstateTypes } = require('./app/controllers/realEstateTypes');
|
||||
const { getRegion, postRegion } = require('./app/controllers/regions');
|
||||
const { getMunicipality, postMunicipality } = require('./app/controllers/municipalities');
|
||||
const { getSize, postSize } = require('./app/controllers/sizes');
|
||||
const { getGardenSize, postGardenSize } = require('./app/controllers/gardenSizes');
|
||||
const { getPrice, postPrice } = require('./app/controllers/prices');
|
||||
const { getQueryReview, postQueryReview } = require('./app/controllers/queryReview');
|
||||
const { getQuerySubmit, postQuerySubmit } = require('./app/controllers/querySubmit');
|
||||
const { getGoAgain } = require('./app/controllers/goAgain');
|
||||
const { getNeighborhood, postNeighborhood } = require('./app/controllers/neighborhoodMap');
|
||||
const { getUnsubscribe } = require('./app/controllers/unsubscribe');
|
||||
const { getRealEstates} = require('./app/controllers/realEstates');
|
||||
const schedule = require('node-schedule');
|
||||
const crawlAll = require('./app/services/crawlerService')
|
||||
const processNotifications = require('./app/services/notificationService')
|
||||
const welcome = require("./app/controllers/welcome").getWelcome;
|
||||
const {
|
||||
getRealEstateTypes,
|
||||
postRealEstateTypes
|
||||
} = require("./app/controllers/realEstateTypes");
|
||||
const { getRegion, postRegion } = require("./app/controllers/regions");
|
||||
const {
|
||||
getMunicipality,
|
||||
postMunicipality
|
||||
} = require("./app/controllers/municipalities");
|
||||
const { getSize, postSize } = require("./app/controllers/sizes");
|
||||
const {
|
||||
getGardenSize,
|
||||
postGardenSize
|
||||
} = require("./app/controllers/gardenSizes");
|
||||
const { getPrice, postPrice } = require("./app/controllers/prices");
|
||||
const {
|
||||
getQueryReview,
|
||||
postQueryReview
|
||||
} = require("./app/controllers/queryReview");
|
||||
const {
|
||||
getQuerySubmit,
|
||||
postQuerySubmit
|
||||
} = require("./app/controllers/querySubmit");
|
||||
const { getGoAgain } = require("./app/controllers/goAgain");
|
||||
const {
|
||||
getNeighborhood,
|
||||
postNeighborhood
|
||||
} = require("./app/controllers/neighborhoodMap");
|
||||
const { getUnsubscribe } = require("./app/controllers/unsubscribe");
|
||||
const { getRealEstates } = require("./app/controllers/realEstates");
|
||||
const { redirect } = require("./app/controllers/redirect");
|
||||
const schedule = require("node-schedule");
|
||||
const crawlAll = require("./app/services/crawlerService");
|
||||
const processNotifications = require("./app/services/notificationService");
|
||||
|
||||
let express = require("express");
|
||||
const path = require("path");
|
||||
@@ -23,7 +42,7 @@ const sendNotification = require("./app/lib/sendNotification");
|
||||
const scrapTheItems = require("./app/lib/scrapTheItems");
|
||||
const sequelize = require("./app/models/index").sequelize;
|
||||
const Twocheckout = require("2checkout-node");
|
||||
const layout = require('express-layout');
|
||||
const layout = require("express-layout");
|
||||
|
||||
const app = express();
|
||||
app.use(bodyParser.json());
|
||||
@@ -31,11 +50,11 @@ app.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
const port = process.env.PORT || 5000;
|
||||
|
||||
app.set('views', path.join(__dirname, '/app/views'));
|
||||
app.set('view engine', 'ejs');
|
||||
app.set("views", path.join(__dirname, "/app/views"));
|
||||
app.set("view engine", "ejs");
|
||||
app.use(layout());
|
||||
|
||||
const compression = require('compression');
|
||||
const compression = require("compression");
|
||||
app.use(compression());
|
||||
|
||||
app.get("/api/sendnotifications", async (req, res) => {
|
||||
@@ -111,7 +130,7 @@ app.post("/api/payforalert", (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
tco.checkout.authorize(params, function (error, data) {
|
||||
tco.checkout.authorize(params, function(error, data) {
|
||||
if (error) {
|
||||
res.send(error.message);
|
||||
} else {
|
||||
@@ -120,64 +139,73 @@ app.post("/api/payforalert", (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/', welcome);
|
||||
app.get('/vrstanekretnine/:request_id', getRealEstateTypes);
|
||||
app.get('/vrstanekretnine', getRealEstateTypes);
|
||||
app.get("/", welcome);
|
||||
app.get("/vrstanekretnine/:request_id", getRealEstateTypes);
|
||||
app.get("/vrstanekretnine", getRealEstateTypes);
|
||||
|
||||
app.post('/vrstanekretnine/:request_id', postRealEstateTypes);
|
||||
app.post('/vrstanekretnine', postRealEstateTypes);
|
||||
app.post("/vrstanekretnine/:request_id", postRealEstateTypes);
|
||||
app.post("/vrstanekretnine", postRealEstateTypes);
|
||||
|
||||
app.get('/grad/:request_id', getRegion);
|
||||
app.post('/grad/:request_id', postRegion);
|
||||
app.get("/grad/:request_id", getRegion);
|
||||
app.post("/grad/:request_id", postRegion);
|
||||
|
||||
app.get('/mjesto/:request_id', getMunicipality);
|
||||
app.post('/mjesto/:request_id', postMunicipality);
|
||||
app.get("/mjesto/:request_id", getMunicipality);
|
||||
app.post("/mjesto/:request_id", postMunicipality);
|
||||
|
||||
app.get('/naselje/:request_id/:municipality', getNeighborhood);
|
||||
app.post('/naselje/:request_id/:municipality', postNeighborhood);
|
||||
app.get("/naselje/:request_id/:municipality", getNeighborhood);
|
||||
app.post("/naselje/:request_id/:municipality", postNeighborhood);
|
||||
|
||||
app.get('/povrsina/:request_id', getSize);
|
||||
app.post('/povrsina/:request_id', postSize);
|
||||
app.get("/povrsina/:request_id", getSize);
|
||||
app.post("/povrsina/:request_id", postSize);
|
||||
|
||||
app.get('/okucnica/:request_id', getGardenSize);
|
||||
app.post('/okucnica/:request_id', postGardenSize);
|
||||
app.get("/okucnica/:request_id", getGardenSize);
|
||||
app.post("/okucnica/:request_id", postGardenSize);
|
||||
|
||||
app.get('/cijena/:request_id', getPrice);
|
||||
app.post('/cijena/:request_id', postPrice);
|
||||
app.get("/cijena/:request_id", getPrice);
|
||||
app.post("/cijena/:request_id", postPrice);
|
||||
|
||||
app.get('/pregled/:request_id', getQueryReview);
|
||||
app.post('/pregled/:request_id', postQueryReview);
|
||||
app.get("/pregled/:request_id", getQueryReview);
|
||||
app.post("/pregled/:request_id", postQueryReview);
|
||||
|
||||
app.get('/posalji/:request_id', getQuerySubmit);
|
||||
app.post('/posalji/:request_id', postQuerySubmit);
|
||||
app.get("/posalji/:request_id", getQuerySubmit);
|
||||
app.post("/posalji/:request_id", postQuerySubmit);
|
||||
|
||||
app.get('/odjava/:request_id', getUnsubscribe);
|
||||
app.get("/odjava/:request_id", getUnsubscribe);
|
||||
|
||||
app.get('/ponovo', getGoAgain);
|
||||
app.get("/ponovo", getGoAgain);
|
||||
|
||||
app.get('/nekretnine/:request_id', getRealEstates);
|
||||
app.get("/nekretnine/:request_id", getRealEstates);
|
||||
|
||||
app.use('/assets', express.static('./app/public'));
|
||||
app.get("/redirect/:id", redirect);
|
||||
|
||||
app.use("/assets", express.static("./app/public"));
|
||||
|
||||
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
|
||||
|
||||
var rule = new schedule.RecurrenceRule();
|
||||
rule.seccond = 1;
|
||||
schedule.scheduleJob(rule, async function () {
|
||||
console.log(new Date(), 'Crawler service started');
|
||||
await crawlAll();
|
||||
console.log(new Date(), 'Crawler service finished, starting Notification service');
|
||||
await processNotifications();
|
||||
console.log(new Date(), 'Notification service finished');
|
||||
});
|
||||
|
||||
/**
|
||||
* Add flat method to Array
|
||||
*/
|
||||
Object.defineProperty(Array.prototype, 'flat', {
|
||||
value: function(depth = 1) {
|
||||
return this.reduce(function (flat, toFlatten) {
|
||||
return flat.concat((Array.isArray(toFlatten) && (depth>1)) ? toFlatten.flat(depth-1) : toFlatten);
|
||||
}, []);
|
||||
}
|
||||
rule.seccond = 1;
|
||||
schedule.scheduleJob(rule, async function() {
|
||||
console.log(new Date(), "Crawler service started");
|
||||
await crawlAll();
|
||||
console.log(
|
||||
new Date(),
|
||||
"Crawler service finished, starting Notification service"
|
||||
);
|
||||
await processNotifications();
|
||||
console.log(new Date(), "Notification service finished");
|
||||
});
|
||||
|
||||
/**
|
||||
* Add flat method to Array
|
||||
*/
|
||||
Object.defineProperty(Array.prototype, "flat", {
|
||||
value: function(depth = 1) {
|
||||
return this.reduce(function(flat, toFlatten) {
|
||||
return flat.concat(
|
||||
Array.isArray(toFlatten) && depth > 1
|
||||
? toFlatten.flat(depth - 1)
|
||||
: toFlatten
|
||||
);
|
||||
}, []);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user