clean code
This commit is contained in:
@@ -1,25 +1,24 @@
|
||||
const db = require('../models/index');
|
||||
const { currentRERequest } = require('../helpers/url');
|
||||
const { currentRERequest } = require('../helpers/url');
|
||||
const { places } = require('../helpers/codes');
|
||||
|
||||
const getNeighborhood = async (req,res) => {
|
||||
let request = await currentRERequest(req);
|
||||
const neighborhoods = places(request.city);
|
||||
const nextStep = req.query.nextStep || '/';
|
||||
res.render('neighborhood', {
|
||||
nextStep,
|
||||
neighborhoods
|
||||
res.render('neighborhood', {
|
||||
nextStep,
|
||||
neighborhoods
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const postgNeighborhood = async (req, res) => {
|
||||
let request = await currentRERequest(req);
|
||||
request.neighborhood = req.body.neighborhood;
|
||||
await request.save();
|
||||
res.send("Result is " + JSON.stringify(request));
|
||||
}
|
||||
res.send("Result is " + JSON.stringify(request));
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
module.exports = {
|
||||
getNeighborhood,
|
||||
postgNeighborhood
|
||||
};
|
||||
|
||||
@@ -6,7 +6,6 @@ const realEstateTypes = [
|
||||
{ ime: "Vikendica", id: "vikendica" }
|
||||
];
|
||||
|
||||
|
||||
const getRealEstateTypes = (req,res) => {
|
||||
const nextStep = req.query.nextStep;
|
||||
res.render('realEstateType', {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const getWelcome = (req,res) => {
|
||||
res.render('welcome', { nextStep: '/vrstanekretnine' } );
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
module.exports = {
|
||||
getWelcome
|
||||
};
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
|
||||
|
||||
const geographies = [
|
||||
{
|
||||
"ime":" Sarajevo",
|
||||
"id":"sarajevo",
|
||||
"olxid": "9",
|
||||
"olxid": "9",
|
||||
"mjesta":[
|
||||
{
|
||||
"ime":"Hadžići",
|
||||
@@ -56,7 +54,7 @@ const geographies = [
|
||||
{
|
||||
"ime":" Unsko-sanski",
|
||||
"id":"unskosanski",
|
||||
"olxid": "9",
|
||||
"olxid": "9",
|
||||
"mjesta":[
|
||||
{
|
||||
"ime":"Bihać",
|
||||
@@ -103,7 +101,7 @@ const geographies = [
|
||||
{
|
||||
"ime":" Posavski",
|
||||
"id":"posavski",
|
||||
"olxid": "15",
|
||||
"olxid": "15",
|
||||
"mjesta":[
|
||||
{
|
||||
"ime":"Domaljevac",
|
||||
@@ -130,7 +128,7 @@ const geographies = [
|
||||
{
|
||||
"ime":" Tuzlanski",
|
||||
"id":"tuzlanski",
|
||||
"olxid": "15",
|
||||
"olxid": "15",
|
||||
"mjesta":[
|
||||
{
|
||||
"ime":"Banovići",
|
||||
@@ -202,7 +200,7 @@ const geographies = [
|
||||
{
|
||||
"ime":" Zeničko-dobojski",
|
||||
"id":"zenickodobojski",
|
||||
"olxid": "15",
|
||||
"olxid": "15",
|
||||
"mjesta":[
|
||||
{
|
||||
"ime":"Breza",
|
||||
@@ -269,7 +267,7 @@ const geographies = [
|
||||
{
|
||||
"ime":" Bosansko-podrinjski",
|
||||
"id":"bosanskopodrinjski",
|
||||
"olxid": "15",
|
||||
"olxid": "15",
|
||||
"mjesta":[
|
||||
{
|
||||
"ime":"Foča",
|
||||
@@ -291,7 +289,7 @@ const geographies = [
|
||||
{
|
||||
"ime":" Srednjobosanski",
|
||||
"id":"srednjobosanski",
|
||||
"olxid": "6",
|
||||
"olxid": "6",
|
||||
"mjesta":[
|
||||
{
|
||||
"ime":"Bugojno",
|
||||
@@ -358,7 +356,7 @@ const geographies = [
|
||||
{
|
||||
"ime":" Hercegovačko-neretvanski",
|
||||
"id":"hercegovackoneretvanski",
|
||||
"olxid": "7",
|
||||
"olxid": "7",
|
||||
"mjesta":[
|
||||
{
|
||||
"ime":"Grad Mostar",
|
||||
@@ -410,7 +408,7 @@ const geographies = [
|
||||
{
|
||||
"ime":" Zapadno-hercegovački",
|
||||
"id":"zapadnohercegovacki",
|
||||
"olxid": "8",
|
||||
"olxid": "8",
|
||||
"mjesta":[
|
||||
{
|
||||
"ime":"Grude",
|
||||
@@ -437,7 +435,7 @@ const geographies = [
|
||||
{
|
||||
"ime":" Livanjski",
|
||||
"id":"livanjski",
|
||||
"olxid": "10",
|
||||
"olxid": "10",
|
||||
"mjesta":[
|
||||
{
|
||||
"ime":"Bosansko Grahovo",
|
||||
@@ -474,7 +472,7 @@ const geographies = [
|
||||
{
|
||||
"ime":" Banjalučka",
|
||||
"id":"banjalučka",
|
||||
"olxid": "14",
|
||||
"olxid": "14",
|
||||
"mjesta":[
|
||||
{
|
||||
"ime":"Banja Luka",
|
||||
@@ -586,7 +584,7 @@ const geographies = [
|
||||
{
|
||||
"ime":" Dobojsko-Bijeljinska",
|
||||
"id":"dobojskobijeljinska",
|
||||
"olxid": "15",
|
||||
"olxid": "15",
|
||||
"mjesta":[
|
||||
{
|
||||
"ime":"Bijeljina",
|
||||
@@ -682,8 +680,8 @@ const geographies = [
|
||||
},
|
||||
{
|
||||
"ime":" Sarajevsko-Zvornička",
|
||||
"id":"sarajevskozvornicka",
|
||||
"olxid": "16",
|
||||
"id":"sarajevskozvornicka",
|
||||
"olxid": "16",
|
||||
"mjesta":[
|
||||
{
|
||||
"ime":"Bratunac",
|
||||
@@ -805,7 +803,7 @@ const geographies = [
|
||||
{
|
||||
"ime":" Trebinjsko-Fočanska",
|
||||
"id":"trebinjskofocanska",
|
||||
"olxid": "17",
|
||||
"olxid": "17",
|
||||
"mjesta":[
|
||||
{
|
||||
"ime":"Berkovići",
|
||||
@@ -862,7 +860,7 @@ const geographies = [
|
||||
{
|
||||
"ime":"Distrikt Brčko",
|
||||
"id":"distriktbrcko",
|
||||
"olxid": "12",
|
||||
"olxid": "12",
|
||||
"mjesta":[
|
||||
{
|
||||
"ime":"Brčko",
|
||||
@@ -872,22 +870,22 @@ const geographies = [
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
];
|
||||
|
||||
const regions = () => {
|
||||
return geographies.map( (g) => ({ ime: g.ime, id: g.id, olxid: g.olxid }) );
|
||||
}
|
||||
return geographies.map( (g) => ({ ime: g.ime, id: g.id, olxid: g.olxid }) );
|
||||
};
|
||||
|
||||
const places = (regionId) => {
|
||||
for (geo of geographies) {
|
||||
for (geo of geographies) {
|
||||
if(geo.id === regionId) {
|
||||
return geo.mjesta;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
regions,
|
||||
places
|
||||
}
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@ const currentRERequest = async (req) => {
|
||||
|
||||
const request = await db.RealEstateRequest.findOne({ where: {uniqueId} });
|
||||
return request;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
currentRERequest
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
const convertToDate = require("./convertToDate");
|
||||
|
||||
function areThereAnyNewItems(lastItemDate, controlDate) {
|
||||
if (!lastItemDate) {
|
||||
return true;
|
||||
}
|
||||
return new Date(controlDate) < convertToDate(lastItemDate);
|
||||
}
|
||||
|
||||
module.exports = areThereAnyNewItems;
|
||||
@@ -1,6 +1,6 @@
|
||||
let fetch = require("node-fetch");
|
||||
let cheerio = require("cheerio");
|
||||
const areThereAnyNewItems = require("./arethereanynewitems");
|
||||
const areThereAnyNewItems = require("./areThereAnyNewItems");
|
||||
|
||||
async function scrapTheItems(url, controlDate, noNewItems = false) {
|
||||
let items = [];
|
||||
@@ -1,11 +1,11 @@
|
||||
const scrapTheItems = require("./scraptheitems");
|
||||
const scrapTheItems = require("./scrapTheItems");
|
||||
const convertToDate = require("./convertToDate");
|
||||
const AWS = require('aws-sdk');
|
||||
AWS.config.update({region: 'eu-central-1'});
|
||||
|
||||
|
||||
async function sendNotification(marketAlert) {
|
||||
const { id, email, olx_url, last_date } = marketAlert;
|
||||
const { id, email, olx_url } = marketAlert;
|
||||
let url =
|
||||
"https://www.olx.ba/pretraga?" + olx_url + "&sort_order=desc&sort_po=datum";
|
||||
let newItems = await scrapTheItems(url);
|
||||
@@ -17,8 +17,8 @@ async function sendNotification(marketAlert) {
|
||||
""
|
||||
);
|
||||
|
||||
// Create sendEmail params
|
||||
var params = {
|
||||
// Create sendEmail params
|
||||
const params = {
|
||||
Destination: { /* required */
|
||||
CcAddresses: [
|
||||
],
|
||||
@@ -50,7 +50,7 @@ async function sendNotification(marketAlert) {
|
||||
|
||||
if (message) {
|
||||
const sendPromise = new AWS.SES({apiVersion: '2010-12-01'}).sendEmail(params).promise();
|
||||
await sendPromise;
|
||||
await sendPromise;
|
||||
return { id, date: String(convertToDate(lastDate)) };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user