diff --git a/app/controllers/municipalities.js b/app/controllers/municipalities.js index bc0fb4d..46fb233 100644 --- a/app/controllers/municipalities.js +++ b/app/controllers/municipalities.js @@ -3,7 +3,7 @@ const { getMunicipalitiesForRegion } = require('../helpers/codes'); const getMunicipality = async (req,res) => { let request = await currentRERequest(req); - const municipalities = getMunicipalitiesForRegion(request.city); + const municipalities = getMunicipalitiesForRegion(request.region); const nextStep = req.query.nextStep || '/'; res.render('municipality', { nextStep, diff --git a/app/controllers/cities.js b/app/controllers/regions.js similarity index 54% rename from app/controllers/cities.js rename to app/controllers/regions.js index ba0030c..44f82e8 100644 --- a/app/controllers/cities.js +++ b/app/controllers/regions.js @@ -1,26 +1,25 @@ const { currentRERequest } = require('../helpers/url'); -const { regions } = require('../helpers/codes'); +const { getRegions } = require('../helpers/codes'); -const cities = regions(); +const regions = getRegions(); - -const getCity = (req,res) => { +const getRegion = (req,res) => { const nextStep = req.query.nextStep || '/'; - res.render('city', { + res.render('region', { nextStep, - cities + regions }); -} +}; -const postCity = async (req, res) => { +const postRegion = async (req, res) => { const request = await currentRERequest(req); const nextStep = req.query.nextStep || `/mjesto/${request.uniqueId}`; - request.city = req.body.city; + request.region = req.body.region; await request.save(); res.redirect(nextStep) -} +}; module.exports = { - getCity, - postCity + getRegion, + postRegion }; diff --git a/app/helpers/codes.js b/app/helpers/codes.js index 962f80f..dff4b75 100644 --- a/app/helpers/codes.js +++ b/app/helpers/codes.js @@ -1,4 +1,4 @@ -const geographies = [ +const regions = [ { "ime":" Sarajevo", "id":"sarajevo", @@ -872,12 +872,12 @@ const geographies = [ } ]; -const regions = () => { - return geographies.map( (g) => ({ ime: g.ime, id: g.id, olxid: g.olxid }) ); +const getRegions = () => { + return regions.map( (g) => ({ ime: g.ime, id: g.id, olxid: g.olxid }) ); }; const getMunicipalitiesForRegion = (regionId) => { - for (geo of geographies) { + for (geo of regions) { if(geo.id === regionId) { return geo.mjesta; } @@ -886,6 +886,6 @@ const getMunicipalitiesForRegion = (regionId) => { }; module.exports = { - regions, + getRegions, getMunicipalitiesForRegion }; 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 536a1b9..7162aee 100644 --- a/app/models/realestaterequest.js +++ b/app/models/realestaterequest.js @@ -11,7 +11,7 @@ module.exports = (sequelize, DataTypes) => { values: ['kuca','stan','vikendica','plac','poslovni_prostor','apartman','garaza'] }, email: DataTypes.STRING, - city: DataTypes.STRING, + region: DataTypes.STRING, municipality: DataTypes.STRING, }, {}); RealEstateRequest.associate = function(models) { diff --git a/app/views/city.ejs b/app/views/region.ejs similarity index 53% rename from app/views/city.ejs rename to app/views/region.ejs index 65fe696..40f2173 100644 --- a/app/views/city.ejs +++ b/app/views/region.ejs @@ -1,13 +1,14 @@ +

U kojoj regiji tražite nekretninu?

-
+
- +
diff --git a/index.js b/index.js index 7ca87df..e81c68b 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ const welcome = require('./app/controllers/welcome').getWelcome; const { getRealEstateTypes, postRealEstateTypes} = require('./app/controllers/realEstateTypes'); -const { getCity, postCity } = require('./app/controllers/cities'); +const { getRegion, postRegion } = require('./app/controllers/regions'); const { getMunicipality, postMunicipality } = require('./app/controllers/municipalities'); let express = require("express"); @@ -115,8 +115,8 @@ app.get('/vrstanekretnine', getRealEstateTypes); app.post('/vrstanekretnine/:request_id', postRealEstateTypes); app.post('/vrstanekretnine', postRealEstateTypes); -app.get('/grad/:request_id', getCity); -app.post('/grad/:request_id', postCity); +app.get('/grad/:request_id', getRegion); +app.post('/grad/:request_id', postRegion); app.get('/mjesto/:request_id', getMunicipality); app.post('/mjesto/:request_id', postMunicipality);