clean code
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
const db = require('../models/index');
|
||||
const { currentRERequest } = require('../helpers/url');
|
||||
const { places } = require('../helpers/codes');
|
||||
|
||||
@@ -10,14 +9,14 @@ const getNeighborhood = async (req,res) => {
|
||||
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));
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getNeighborhood,
|
||||
|
||||
@@ -6,7 +6,6 @@ const realEstateTypes = [
|
||||
{ ime: "Vikendica", id: "vikendica" }
|
||||
];
|
||||
|
||||
|
||||
const getRealEstateTypes = (req,res) => {
|
||||
const nextStep = req.query.nextStep;
|
||||
res.render('realEstateType', {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const getWelcome = (req,res) => {
|
||||
res.render('welcome', { nextStep: '/vrstanekretnine' } );
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getWelcome
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
const geographies = [
|
||||
{
|
||||
"ime":" Sarajevo",
|
||||
@@ -872,11 +870,11 @@ const geographies = [
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
];
|
||||
|
||||
const regions = () => {
|
||||
return geographies.map( (g) => ({ ime: g.ime, id: g.id, olxid: g.olxid }) );
|
||||
}
|
||||
};
|
||||
|
||||
const places = (regionId) => {
|
||||
for (geo of geographies) {
|
||||
@@ -885,9 +883,9 @@ const places = (regionId) => {
|
||||
}
|
||||
}
|
||||
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);
|
||||
@@ -18,7 +18,7 @@ async function sendNotification(marketAlert) {
|
||||
);
|
||||
|
||||
// Create sendEmail params
|
||||
var params = {
|
||||
const params = {
|
||||
Destination: { /* required */
|
||||
CcAddresses: [
|
||||
],
|
||||
18
index.js
18
index.js
@@ -7,8 +7,8 @@ let express = require("express");
|
||||
const path = require("path");
|
||||
const bodyParser = require("body-parser");
|
||||
const MarketAlert = require("./app/models/marketalert");
|
||||
const sendNotification = require("./app/lib/sendnotification");
|
||||
const scrapTheItems = require("./app/lib/scraptheitems");
|
||||
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');
|
||||
@@ -26,7 +26,7 @@ app.use(layout());
|
||||
const compression = require('compression');
|
||||
app.use(compression());
|
||||
|
||||
app.get("/api/sendnotifications", async function(req, res) {
|
||||
app.get("/api/sendnotifications", async (req, res) => {
|
||||
let marketAlerts = await MarketAlert.findAll();
|
||||
|
||||
let lastDateUpdate = await Promise.all(
|
||||
@@ -59,7 +59,7 @@ app.get("/api/items/:url", async (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.post("/api/marketalerts", function(req, res) {
|
||||
app.post("/api/marketalerts", (req, res) => {
|
||||
const { email, last_date, olx_url } = req.body;
|
||||
console.log(email, last_date, olx_url);
|
||||
sequelize.sync().then(() => {
|
||||
@@ -75,7 +75,7 @@ app.post("/api/marketalerts", function(req, res) {
|
||||
});
|
||||
});
|
||||
|
||||
app.post("/api/payforalert", function(request, response) {
|
||||
app.post("/api/payforalert", (req, res) => {
|
||||
let tco = new Twocheckout({
|
||||
sellerId: "901402692",
|
||||
privateKey: "A28DCE5F-9292-405C-8161-F84D8BB83AFC",
|
||||
@@ -84,7 +84,7 @@ app.post("/api/payforalert", function(request, response) {
|
||||
|
||||
let params = {
|
||||
merchantOrderId: "123",
|
||||
token: request.body.token,
|
||||
token: req.body.token,
|
||||
currency: "USD",
|
||||
total: "2.00",
|
||||
billingAddr: {
|
||||
@@ -94,16 +94,16 @@ app.post("/api/payforalert", function(request, response) {
|
||||
state: "BiH",
|
||||
zipCode: "71000",
|
||||
country: "BiH",
|
||||
email: request.body.email,
|
||||
email: req.body.email,
|
||||
phoneNumber: "5555555555"
|
||||
}
|
||||
};
|
||||
|
||||
tco.checkout.authorize(params, function(error, data) {
|
||||
if (error) {
|
||||
response.send(error.message);
|
||||
res.send(error.message);
|
||||
} else {
|
||||
response.send(data.response.responseMsg);
|
||||
res.send(data.response.responseMsg);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user