diff --git a/README.md b/README.md index 0c19539..5baaa51 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,36 @@ -# web - +# MarketAlert The purpose of this project is to build a web application that enables subscribing to notifications when new products are published on various ad based marketplaces. The MVP will be only based on OLX.ba -Create postgres docker image -docker build -t marketalerts . +## Setup -Run postgres image with: -docker run --name pg_test -d -p 5432:5432 marketalerts +### Setup with npm commands -Run migrations in app folder -npx sequelize db:migrate +1. Run setup script +`npm run setup` +this will create and run postgres image and then execute migrations -Run app with: -$ npm install -$ npm start +2. Install packages +`npm install` + +3. Run app +`npm start` to run app without restart on changes or +`npm run start-mon` to run app with automatic restart on code change + + +### Manual setup + +1. Create postgres docker image +`docker build -t marketalerts .` + +2. Run postgres image with +`docker run --name pg_marketalerts -d -p 5432:5432 marketalerts` + +3. Install packages +`npm install` + +4. Run migrations from `app` folder +`npm run migrate` or `npx sequelize db:migrate` + +5. Run app +`npm start` or `npm run start-mon` to run app with automatic restart on code change diff --git a/app/controllers/city.js b/app/controllers/city.js deleted file mode 100644 index 0be41f4..0000000 --- a/app/controllers/city.js +++ /dev/null @@ -1,27 +0,0 @@ -const db = require('../models/index'); -const { currentRERequest } = require('../helpers/url'); -const { regions } = require('../helpers/codes'); - -const cities = regions(); - - -const getCity = (req,res) => { - const nextStep = req.query.nextStep || '/'; - res.render('city', { - nextStep, - cities - }); -} - -const postCity = async (req, res) => { - const request = await currentRERequest(req); - const nextStep = req.query.nextStep || `/mjesto/${request.uniqueId}`; - request.city = req.body.city; - await request.save(); - res.redirect(nextStep) -} - -module.exports = { - getCity, - postCity -}; diff --git a/app/controllers/municipalities.js b/app/controllers/municipalities.js new file mode 100644 index 0000000..46fb233 --- /dev/null +++ b/app/controllers/municipalities.js @@ -0,0 +1,24 @@ +const { currentRERequest } = require('../helpers/url'); +const { getMunicipalitiesForRegion } = require('../helpers/codes'); + +const getMunicipality = async (req,res) => { + let request = await currentRERequest(req); + const municipalities = getMunicipalitiesForRegion(request.region); + const nextStep = req.query.nextStep || '/'; + res.render('municipality', { + nextStep, + municipalities + }); +}; + +const postMunicipality = async (req, res) => { + let request = await currentRERequest(req); + request.municipality = req.body.municipality; + await request.save(); + res.send("Result is " + JSON.stringify(request)); +}; + +module.exports = { + getMunicipality, + postMunicipality +}; diff --git a/app/controllers/neighborhoods.js b/app/controllers/neighborhoods.js deleted file mode 100644 index 031a120..0000000 --- a/app/controllers/neighborhoods.js +++ /dev/null @@ -1,25 +0,0 @@ -const db = require('../models/index'); -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 - }); -} - -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, - postgNeighborhood -}; diff --git a/app/controllers/real_estate_types.js b/app/controllers/realEstateTypes.js similarity index 64% rename from app/controllers/real_estate_types.js rename to app/controllers/realEstateTypes.js index 40f5d6e..125cb5f 100644 --- a/app/controllers/real_estate_types.js +++ b/app/controllers/realEstateTypes.js @@ -1,19 +1,18 @@ const db = require('../models/index'); const realEstateTypes = [ - { ime: "Kuća", id: "kuca" }, - { ime: "Stan", id: "stan" }, + { ime: "Kuća", id: "kuca" }, + { ime: "Stan", id: "stan" }, { ime: "Vikendica", id: "vikendica" } ]; - const getRealEstateTypes = (req,res) => { - const nextStep = req.query.nextStep; - res.render('real_estate_type', { - nextStep, - realEstateTypes: realEstateTypes + const nextStep = req.query.nextStep; + res.render('realEstateType', { + nextStep, + realEstateTypes: realEstateTypes }); -} +}; const postRealEstateTypes = (req, res) => { let nextStep = req.query.nextStep; @@ -21,14 +20,13 @@ const postRealEstateTypes = (req, res) => { realEstateType: req.body.realestatetype }).then( (result) => { nextStep = nextStep || `/grad/${result.uniqueId}`; - res.redirect(nextStep); + res.redirect(nextStep); }).catch( (e) => { res.send(e); - }); - -} + }); +}; -module.exports = { +module.exports = { getRealEstateTypes, postRealEstateTypes }; diff --git a/app/controllers/regions.js b/app/controllers/regions.js new file mode 100644 index 0000000..44f82e8 --- /dev/null +++ b/app/controllers/regions.js @@ -0,0 +1,25 @@ +const { currentRERequest } = require('../helpers/url'); +const { getRegions } = require('../helpers/codes'); + +const regions = getRegions(); + +const getRegion = (req,res) => { + const nextStep = req.query.nextStep || '/'; + res.render('region', { + nextStep, + regions + }); +}; + +const postRegion = async (req, res) => { + const request = await currentRERequest(req); + const nextStep = req.query.nextStep || `/mjesto/${request.uniqueId}`; + request.region = req.body.region; + await request.save(); + res.redirect(nextStep) +}; + +module.exports = { + getRegion, + postRegion +}; diff --git a/app/controllers/welcome.js b/app/controllers/welcome.js index 0c638ad..8ded508 100644 --- a/app/controllers/welcome.js +++ b/app/controllers/welcome.js @@ -1,7 +1,7 @@ const getWelcome = (req,res) => { res.render('welcome', { nextStep: '/vrstanekretnine' } ); -} +}; -module.exports = { +module.exports = { getWelcome }; diff --git a/app/helpers/codes.js b/app/helpers/codes.js index 8cfc6be..53272d0 100644 --- a/app/helpers/codes.js +++ b/app/helpers/codes.js @@ -1,893 +1,891 @@ - - -const geographies = [ +const regions = [ { - "ime":" Sarajevo", + "name":" Sarajevo", "id":"sarajevo", - "olxid": "9", - "mjesta":[ + "olxid": "9", + "municipalities":[ { - "ime":"Hadžići", + "name":"Hadžići", "id":"hadii", "olxid":"3817" }, { - "ime":"Ilidža", + "name":"Ilidža", "id":"ilida", "olxid":"3879" }, { - "ime":"Ilijaš", + "name":"Ilijaš", "id":"ilija", "olxid":"3892" }, { - "ime":"Sarajevo - Centar", + "name":"Sarajevo - Centar", "id":"sarajevocentar", "olxid":"3812" }, { - "ime":"Sarajevo-Novi Grad", + "name":"Sarajevo-Novi Grad", "id":"sarajevonovigrad", "olxid":"3969" }, { - "ime":"Sarajevo-Novo Sarajevo", + "name":"Sarajevo-Novo Sarajevo", "id":"sarajevonovosarajevo", "olxid":"5896" }, { - "ime":"Sarajevo-Stari Grad", + "name":"Sarajevo-Stari Grad", "id":"sarajevostarigrad", "olxid":"4048" }, { - "ime":"Trnovo", + "name":"Trnovo", "id":"trnovo", "olxid":"4063" }, { - "ime":"Vogošća", + "name":"Vogošća", "id":"vogoa", "olxid":"4126" } ] }, { - "ime":" Unsko-sanski", + "name":" Unsko-sanski", "id":"unskosanski", - "olxid": "9", - "mjesta":[ + "olxid": "9", + "municipalities":[ { - "ime":"Bihać", + "name":"Bihać", "id":"biha", "olxid":"75" }, { - "ime":"Bosanska Krupa", + "name":"Bosanska Krupa", "id":"bosanskakrupa", "olxid":"373" }, { - "ime":"Bosanski Petrovac", + "name":"Bosanski Petrovac", "id":"bosanskipetrovac", "olxid":"504" }, { - "ime":"Bužim", + "name":"Bužim", "id":"buim", "olxid":"374" }, { - "ime":"Cazin", + "name":"Cazin", "id":"cazin", "olxid":"857" }, { - "ime":"Ključ", + "name":"Ključ", "id":"klju", "olxid":"2362" }, { - "ime":"Sanski Most", + "name":"Sanski Most", "id":"sanskimost", "olxid":"3738" }, { - "ime":"Velika Kladuša", + "name":"Velika Kladuša", "id":"velikakladua", "olxid":"5122" } ] }, { - "ime":" Posavski", + "name":" Posavski", "id":"posavski", - "olxid": "15", - "mjesta":[ + "olxid": "15", + "municipalities":[ { - "ime":"Domaljevac", + "name":"Domaljevac", "id":"domaljevac", "olxid":"6144" }, { - "ime":"Odžak", + "name":"Odžak", "id":"odak", "olxid":"424" }, { - "ime":"Orašje", + "name":"Orašje", "id":"oraje", "olxid":"3252" }, { - "ime":"Šamac", + "name":"Šamac", "id":"amac", "olxid":"540" } ] }, { - "ime":" Tuzlanski", + "name":" Tuzlanski", "id":"tuzlanski", - "olxid": "15", - "mjesta":[ + "olxid": "15", + "municipalities":[ { - "ime":"Banovići", + "name":"Banovići", "id":"banovii", "olxid":"2" }, { - "ime":"Doboj-Istok", + "name":"Doboj-Istok", "id":"dobojistok", "olxid":"1090" }, { - "ime":"Gradačac", + "name":"Gradačac", "id":"gradaac", "olxid":"1854" }, { - "ime":"Gračanica", + "name":"Gračanica", "id":"graanica", "olxid":"1826" }, { - "ime":"Kalesija", + "name":"Kalesija", "id":"kalesija", "olxid":"2129" }, { - "ime":"Kladanj", + "name":"Kladanj", "id":"kladanj", "olxid":"2319" }, { - "ime":"Lukavac", + "name":"Lukavac", "id":"lukavac", "olxid":"2840" }, { - "ime":"Sapna", + "name":"Sapna", "id":"sapna", "olxid":"5699" }, { - "ime":"Srebrenik", + "name":"Srebrenik", "id":"srebrenik", "olxid":"4391" }, { - "ime":"Teočak", + "name":"Teočak", "id":"teoak", "olxid":"5010" }, { - "ime":"Tuzla", + "name":"Tuzla", "id":"tuzla", "olxid":"4944" }, { - "ime":"Čelić", + "name":"Čelić", "id":"eli", "olxid":"2801" }, { - "ime":"Živinice", + "name":"Živinice", "id":"ivinice", "olxid":"5774" } ] }, { - "ime":" Zeničko-dobojski", + "name":" Zeničko-dobojski", "id":"zenickodobojski", - "olxid": "15", - "mjesta":[ + "olxid": "15", + "municipalities":[ { - "ime":"Breza", + "name":"Breza", "id":"breza", "olxid":"704" }, { - "ime":"Doboj-Jug", + "name":"Doboj-Jug", "id":"dobojjug", "olxid":"1122" }, { - "ime":"Kakanj", + "name":"Kakanj", "id":"kakanj", "olxid":"2022" }, { - "ime":"Maglaj", + "name":"Maglaj", "id":"maglaj", "olxid":"2941" }, { - "ime":"Olovo", + "name":"Olovo", "id":"olovo", "olxid":"1925" }, { - "ime":"Tešanj", + "name":"Tešanj", "id":"teanj", "olxid":"4594" }, { - "ime":"Usora", + "name":"Usora", "id":"usora", "olxid":"1087" }, { - "ime":"Vareš", + "name":"Vareš", "id":"vare", "olxid":"5037" }, { - "ime":"Visoko", + "name":"Visoko", "id":"visoko", "olxid":"5171" }, { - "ime":"Zavidovići", + "name":"Zavidovići", "id":"zavidovii", "olxid":"5548" }, { - "ime":"Zenica", + "name":"Zenica", "id":"zenica", "olxid":"4571" }, { - "ime":"Žepče", + "name":"Žepče", "id":"epe", "olxid":"2940" } ] }, { - "ime":" Bosansko-podrinjski", + "name":" Bosansko-podrinjski", "id":"bosanskopodrinjski", - "olxid": "15", - "mjesta":[ + "olxid": "15", + "municipalities":[ { - "ime":"Foča", + "name":"Foča", "id":"foa", "olxid":"1289" }, { - "ime":"Goražde", + "name":"Goražde", "id":"gorade", "olxid":"1588" }, { - "ime":"Pale", + "name":"Pale", "id":"pale", "olxid":"3546" } ] }, { - "ime":" Srednjobosanski", + "name":" Srednjobosanski", "id":"srednjobosanski", - "olxid": "6", - "mjesta":[ + "olxid": "6", + "municipalities":[ { - "ime":"Bugojno", + "name":"Bugojno", "id":"bugojno", "olxid":"732" }, { - "ime":"Busovača", + "name":"Busovača", "id":"busovaa", "olxid":"810" }, { - "ime":"Dobretići", + "name":"Dobretići", "id":"dobretii", "olxid":"4151" }, { - "ime":"Donji Vakuf", + "name":"Donji Vakuf", "id":"donjivakuf", "olxid":"1160" }, { - "ime":"Fojnica", + "name":"Fojnica", "id":"fojnica", "olxid":"1407" }, { - "ime":"Gornji Vakuf - Uskoplje", + "name":"Gornji Vakuf - Uskoplje", "id":"gornjivakufuskoplje", "olxid":"1775" }, { - "ime":"Jajce", + "name":"Jajce", "id":"jajce", "olxid":"1960" }, { - "ime":"Kiseljak", + "name":"Kiseljak", "id":"kiseljak", "olxid":"2237" }, { - "ime":"Kreševo", + "name":"Kreševo", "id":"kreevo", "olxid":"2608" }, { - "ime":"Novi Travnik", + "name":"Novi Travnik", "id":"novitravnik", "olxid":"3477" }, { - "ime":"Travnik", + "name":"Travnik", "id":"travnik", "olxid":"4678" }, { - "ime":"Vitez", + "name":"Vitez", "id":"vitez", "olxid":"5422" } ] }, { - "ime":" Hercegovačko-neretvanski", + "name":" Hercegovačko-neretvanski", "id":"hercegovackoneretvanski", - "olxid": "7", - "mjesta":[ + "olxid": "7", + "municipalities":[ { - "ime":"Grad Mostar", + "name":"Grad Mostar", "id":"gradmostar", "olxid":"3017" }, { - "ime":"Jablanica", + "name":"Jablanica", "id":"jablanica", "olxid":"1930" }, { - "ime":"Konjic", + "name":"Konjic", "id":"konjic", "olxid":"2169" }, { - "ime":"Neum", + "name":"Neum", "id":"neum", "olxid":"3111" }, { - "ime":"Prozor", + "name":"Prozor", "id":"prozor", "olxid":"3421" }, { - "ime":"Ravno", + "name":"Ravno", "id":"ravno", "olxid":"4769" }, { - "ime":"Stolac", + "name":"Stolac", "id":"stolac", "olxid":"4439" }, { - "ime":"Čapljina", + "name":"Čapljina", "id":"apljina", "olxid":"947" }, { - "ime":"Čitluk", + "name":"Čitluk", "id":"itluk", "olxid":"1009" } ] }, { - "ime":" Zapadno-hercegovački", + "name":" Zapadno-hercegovački", "id":"zapadnohercegovacki", - "olxid": "8", - "mjesta":[ + "olxid": "8", + "municipalities":[ { - "ime":"Grude", + "name":"Grude", "id":"grude", "olxid":"1892" }, { - "ime":"Ljubuški", + "name":"Ljubuški", "id":"ljubuki", "olxid":"2905" }, { - "ime":"Posušje", + "name":"Posušje", "id":"posuje", "olxid":"3268" }, { - "ime":"Široki Brijeg", + "name":"Široki Brijeg", "id":"irokibrijeg", "olxid":"2708" } ] }, { - "ime":" Livanjski", + "name":" Livanjski", "id":"livanjski", - "olxid": "10", - "mjesta":[ + "olxid": "10", + "municipalities":[ { - "ime":"Bosansko Grahovo", + "name":"Bosansko Grahovo", "id":"bosanskograhovo", "olxid":"560" }, { - "ime":"Drvar", + "name":"Drvar", "id":"drvar", "olxid":"4640" }, { - "ime":"Glamoč", + "name":"Glamoč", "id":"glamo", "olxid":"1533" }, { - "ime":"Kupres", + "name":"Kupres", "id":"kupres", "olxid":"2635" }, { - "ime":"Livno", + "name":"Livno", "id":"livno", "olxid":"2741" }, { - "ime":"Tomislavgrad", + "name":"Tomislavgrad", "id":"tomislavgrad", "olxid":"1228" } ] }, { - "ime":" Banjalučka", + "name":" Banjalučka", "id":"banjalučka", - "olxid": "14", - "mjesta":[ + "olxid": "14", + "municipalities":[ { - "ime":"Banja Luka", + "name":"Banja Luka", "id":"banjaluka", "olxid":"21" }, { - "ime":"Gradiška", + "name":"Gradiška", "id":"gradika", "olxid":"305" }, { - "ime":"Istočni Drvar", + "name":"Istočni Drvar", "id":"istonidrvar", "olxid":"4662" }, { - "ime":"Jezero", + "name":"Jezero", "id":"jezero", "olxid":"1965" }, { - "ime":"Kneževo", + "name":"Kneževo", "id":"kneevo", "olxid":"4147" }, { - "ime":"Kostajnica", + "name":"Kostajnica", "id":"kostajnica", "olxid":"6142" }, { - "ime":"Kotor Varoš", + "name":"Kotor Varoš", "id":"kotorvaro", "olxid":"2574" }, { - "ime":"Kozarska Dubica", + "name":"Kozarska Dubica", "id":"kozarskadubica", "olxid":"244" }, { - "ime":"Krupa na uni", + "name":"Krupa na uni", "id":"krupanauni", "olxid":"382" }, { - "ime":"Kupres ", + "name":"Kupres ", "id":"kupres", "olxid":"2654" }, { - "ime":"Laktaši", + "name":"Laktaši", "id":"laktai", "olxid":"2671" }, { - "ime":"Mrkonjić Grad", + "name":"Mrkonjić Grad", "id":"mrkonjigrad", "olxid":"3073" }, { - "ime":"Novi Grad", + "name":"Novi Grad", "id":"novigrad", "olxid":"444" }, { - "ime":"Oštra Luka", + "name":"Oštra Luka", "id":"otraluka", "olxid":"3737" }, { - "ime":"Petrovac", + "name":"Petrovac", "id":"petrovac", "olxid":"515" }, { - "ime":"Prijedor", + "name":"Prijedor", "id":"prijedor", "olxid":"3287" }, { - "ime":"Prnjavor", + "name":"Prnjavor", "id":"prnjavor", "olxid":"3358" }, { - "ime":"Ribnik", + "name":"Ribnik", "id":"ribnik", "olxid":"2365" }, { - "ime":"Srbac", + "name":"Srbac", "id":"srbac", "olxid":"4271" }, { - "ime":"Čelinac", + "name":"Čelinac", "id":"elinac", "olxid":"979" }, { - "ime":"Šipovo", + "name":"Šipovo", "id":"ipovo", "olxid":"4509" } ] }, { - "ime":" Dobojsko-Bijeljinska", + "name":" Dobojsko-Bijeljinska", "id":"dobojskobijeljinska", - "olxid": "15", - "mjesta":[ + "olxid": "15", + "municipalities":[ { - "ime":"Bijeljina", + "name":"Bijeljina", "id":"bijeljina", "olxid":"123" }, { - "ime":"Bosanski Brod", + "name":"Bosanski Brod", "id":"bosanskibrod", "olxid":"421" }, { - "ime":"Derventa", + "name":"Derventa", "id":"derventa", "olxid":"1030" }, { - "ime":"Doboj", + "name":"Doboj", "id":"doboj", "olxid":"1088" }, { - "ime":"Donji Žabar", + "name":"Donji Žabar", "id":"donjiabar", "olxid":"3254" }, { - "ime":"Lopare", + "name":"Lopare", "id":"lopare", "olxid":"2800" }, { - "ime":"Lukavac", + "name":"Lukavac", "id":"lukavac", "olxid":"6029" }, { - "ime":"Modriča", + "name":"Modriča", "id":"modria", "olxid":"2996" }, { - "ime":"Pelagićevo", + "name":"Pelagićevo", "id":"pelagievo", "olxid":"1856" }, { - "ime":"Petrovo", + "name":"Petrovo", "id":"petrovo", "olxid":"1827" }, { - "ime":"Stanari", + "name":"Stanari", "id":"stanari", "olxid":"1148" }, { - "ime":"Teslić", + "name":"Teslić", "id":"tesli", "olxid":"4549" }, { - "ime":"Tešanj", + "name":"Tešanj", "id":"teanj", "olxid":"4636" }, { - "ime":"Travnik", + "name":"Travnik", "id":"travnik", "olxid":"4692" }, { - "ime":"Tuzla", + "name":"Tuzla", "id":"tuzla", "olxid":"4966" }, { - "ime":"Ugljevik", + "name":"Ugljevik", "id":"ugljevik", "olxid":"5009" }, { - "ime":"Vukosavlje", + "name":"Vukosavlje", "id":"vukosavlje", "olxid":"3197" }, { - "ime":"Šamac", + "name":"Šamac", "id":"amac", "olxid":"539" } ] }, { - "ime":" Sarajevsko-Zvornička", - "id":"sarajevskozvornicka", - "olxid": "16", - "mjesta":[ + "name":" Sarajevsko-Zvornička", + "id":"sarajevskozvornicka", + "olxid": "16", + "municipalities":[ { - "ime":"Bratunac", + "name":"Bratunac", "id":"bratunac", "olxid":"595" }, { - "ime":"Han Pijesak", + "name":"Han Pijesak", "id":"hanpijesak", "olxid":"1904" }, { - "ime":"Ilijaš", + "name":"Ilijaš", "id":"ilija", "olxid":"3947" }, { - "ime":"Istočni Stari Grad", + "name":"Istočni Stari Grad", "id":"istonistarigrad", "olxid":"4049" }, { - "ime":"Kasindo", + "name":"Kasindo", "id":"kasindo", "olxid":"3880" }, { - "ime":"Kladanj", + "name":"Kladanj", "id":"kladanj", "olxid":"2325" }, { - "ime":"Lukavica", + "name":"Lukavica", "id":"lukavica", "olxid":"3971" }, { - "ime":"Milići", + "name":"Milići", "id":"milii", "olxid":"6143" }, { - "ime":"Olovo", + "name":"Olovo", "id":"olovo", "olxid":"3221" }, { - "ime":"Osmaci", + "name":"Osmaci", "id":"osmaci", "olxid":"2128" }, { - "ime":"Pale", + "name":"Pale", "id":"pale", "olxid":"3978" }, { - "ime":"Rogatica", + "name":"Rogatica", "id":"rogatica", "olxid":"3529" }, { - "ime":"Rudo", + "name":"Rudo", "id":"rudo", "olxid":"3648" }, { - "ime":"Sarajevo-Novi Grad", + "name":"Sarajevo-Novi Grad", "id":"sarajevonovigrad", "olxid":"6069" }, { - "ime":"Sokolac", + "name":"Sokolac", "id":"sokolac", "olxid":"4183" }, { - "ime":"Srebrenica", + "name":"Srebrenica", "id":"srebrenica", "olxid":"4310" }, { - "ime":"Trnovo", + "name":"Trnovo", "id":"trnovo", "olxid":"4067" }, { - "ime":"Ustiprača", + "name":"Ustiprača", "id":"ustipraa", "olxid":"1593" }, { - "ime":"Višegrad", + "name":"Višegrad", "id":"viegrad", "olxid":"5259" }, { - "ime":"Vlasenica", + "name":"Vlasenica", "id":"vlasenica", "olxid":"5456" }, { - "ime":"Zvornik", + "name":"Zvornik", "id":"zvornik", "olxid":"5684" }, { - "ime":"Šekovići", + "name":"Šekovići", "id":"ekovii", "olxid":"4475" }, { - "ime":"Žepa", + "name":"Žepa", "id":"epa", "olxid":"1906" } ] }, { - "ime":" Trebinjsko-Fočanska", + "name":" Trebinjsko-Fočanska", "id":"trebinjskofocanska", - "olxid": "17", - "mjesta":[ + "olxid": "17", + "municipalities":[ { - "ime":"Berkovići", + "name":"Berkovići", "id":"berkovii", "olxid":"4441" }, { - "ime":"Bileća", + "name":"Bileća", "id":"bilea", "olxid":"183" }, { - "ime":"Foča", + "name":"Foča", "id":"foa", "olxid":"1287" }, { - "ime":"Gacko", + "name":"Gacko", "id":"gacko", "olxid":"1462" }, { - "ime":"Istočni Mostar", + "name":"Istočni Mostar", "id":"istonimostar", "olxid":"3038" }, { - "ime":"Kalinovik", + "name":"Kalinovik", "id":"kalinovik", "olxid":"2164" }, { - "ime":"Ljubinje", + "name":"Ljubinje", "id":"ljubinje", "olxid":"2884" }, { - "ime":"Nevesinje", + "name":"Nevesinje", "id":"nevesinje", "olxid":"3138" }, { - "ime":"Trebinje", + "name":"Trebinje", "id":"trebinje", "olxid":"4766" }, { - "ime":"Čajniče", + "name":"Čajniče", "id":"ajnie", "olxid":"911" } ] }, { - "ime":"Distrikt Brčko", + "name":"Distrikt Brčko", "id":"distriktbrcko", - "olxid": "12", - "mjesta":[ + "olxid": "12", + "municipalities":[ { - "ime":"Brčko", + "name":"Brčko", "id":"brko", "olxid":"12" } ] } -] +]; -const regions = () => { - return geographies.map( (g) => ({ ime: g.ime, id: g.id, olxid: g.olxid }) ); -} +const getRegions = () => { + return regions.map( (g) => ({ name: g.name, id: g.id, olxid: g.olxid }) ); +}; -const places = (regionId) => { - for (geo of geographies) { +const getMunicipalitiesForRegion = (regionId) => { + for (geo of regions) { if(geo.id === regionId) { - return geo.mjesta; + return geo.municipalities; } } - return null; -} + return null; +}; module.exports = { - regions, - places -} + getRegions, + getMunicipalitiesForRegion +}; diff --git a/app/helpers/url.js b/app/helpers/url.js index 9c685dd..81a73b4 100644 --- a/app/helpers/url.js +++ b/app/helpers/url.js @@ -6,8 +6,8 @@ const currentRERequest = async (req) => { const request = await db.RealEstateRequest.findOne({ where: {uniqueId} }); return request; -} +}; module.exports = { currentRERequest -} +}; diff --git a/app/lib/arethereanynewitems.js b/app/lib/areThereAnyNewItems.js similarity index 99% rename from app/lib/arethereanynewitems.js rename to app/lib/areThereAnyNewItems.js index 39f0730..e886d7a 100644 --- a/app/lib/arethereanynewitems.js +++ b/app/lib/areThereAnyNewItems.js @@ -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; diff --git a/app/lib/scraptheitems.js b/app/lib/scrapTheItems.js similarity index 94% rename from app/lib/scraptheitems.js rename to app/lib/scrapTheItems.js index 75a9189..fc749fa 100644 --- a/app/lib/scraptheitems.js +++ b/app/lib/scrapTheItems.js @@ -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 = []; diff --git a/app/lib/sendnotification.js b/app/lib/sendNotification.js similarity index 87% rename from app/lib/sendnotification.js rename to app/lib/sendNotification.js index 81eac63..aeb5c58 100644 --- a/app/lib/sendnotification.js +++ b/app/lib/sendNotification.js @@ -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)) }; } } diff --git a/app/migrations/20190516180226-rename-place-column.js b/app/migrations/20190516180226-rename-place-column.js new file mode 100644 index 0000000..55f6484 --- /dev/null +++ b/app/migrations/20190516180226-rename-place-column.js @@ -0,0 +1,19 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.renameColumn( + 'RealEstateRequests', + 'place', + 'municipality' + ); + }, + + down: (queryInterface, Sequelize) => { + return queryInterface.renameColumn( + 'RealEstateRequests', + 'municipality', + 'place' + ); + } +}; diff --git a/app/migrations/20190516222240-rename-city-column.js b/app/migrations/20190516222240-rename-city-column.js new file mode 100644 index 0000000..7b8742e --- /dev/null +++ b/app/migrations/20190516222240-rename-city-column.js @@ -0,0 +1,19 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.renameColumn( + 'RealEstateRequests', + 'city', + 'region' + ); + }, + + down: (queryInterface, Sequelize) => { + return queryInterface.renameColumn( + 'RealEstateRequests', + 'region', + 'city' + ); + } +}; diff --git a/app/models/realestaterequest.js b/app/models/realestaterequest.js index 847b914..7162aee 100644 --- a/app/models/realestaterequest.js +++ b/app/models/realestaterequest.js @@ -10,9 +10,9 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.ENUM, values: ['kuca','stan','vikendica','plac','poslovni_prostor','apartman','garaza'] }, - email: DataTypes.STRING, - city: DataTypes.STRING, - place: DataTypes.STRING, + email: DataTypes.STRING, + region: DataTypes.STRING, + municipality: DataTypes.STRING, }, {}); RealEstateRequest.associate = function(models) { // associations can be defined here diff --git a/app/views/municipality.ejs b/app/views/municipality.ejs new file mode 100644 index 0000000..2f83bb6 --- /dev/null +++ b/app/views/municipality.ejs @@ -0,0 +1,31 @@ + +