From 42505a7089255e08f97c6871385ed8f115e73183 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Thu, 16 May 2019 23:32:18 +0200 Subject: [PATCH] change column name from 'place' to 'municipality' --- app/controllers/municipalities.js | 24 ++++++++++++++ app/controllers/neighborhoods.js | 24 -------------- app/helpers/codes.js | 4 +-- .../20190516180226-rename-place-column.js | 19 ++++++++++++ app/models/realestaterequest.js | 4 +-- app/views/municipality.ejs | 31 +++++++++++++++++++ app/views/neighborhood.ejs | 31 ------------------- index.js | 6 ++-- 8 files changed, 81 insertions(+), 62 deletions(-) create mode 100644 app/controllers/municipalities.js delete mode 100644 app/controllers/neighborhoods.js create mode 100644 app/migrations/20190516180226-rename-place-column.js create mode 100644 app/views/municipality.ejs delete mode 100644 app/views/neighborhood.ejs diff --git a/app/controllers/municipalities.js b/app/controllers/municipalities.js new file mode 100644 index 0000000..bc0fb4d --- /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.city); + 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 513c012..0000000 --- a/app/controllers/neighborhoods.js +++ /dev/null @@ -1,24 +0,0 @@ -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/helpers/codes.js b/app/helpers/codes.js index e0ebf90..962f80f 100644 --- a/app/helpers/codes.js +++ b/app/helpers/codes.js @@ -876,7 +876,7 @@ const regions = () => { return geographies.map( (g) => ({ ime: g.ime, id: g.id, olxid: g.olxid }) ); }; -const places = (regionId) => { +const getMunicipalitiesForRegion = (regionId) => { for (geo of geographies) { if(geo.id === regionId) { return geo.mjesta; @@ -887,5 +887,5 @@ const places = (regionId) => { module.exports = { regions, - places + getMunicipalitiesForRegion }; 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/models/realestaterequest.js b/app/models/realestaterequest.js index 847b914..536a1b9 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, + email: DataTypes.STRING, city: DataTypes.STRING, - place: 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..626b9b7 --- /dev/null +++ b/app/views/municipality.ejs @@ -0,0 +1,31 @@ + +
+

U kojem mjestu tražite nekretninu?

+
+ +
+
+
    + <% for(const municipality of municipalities) { %> +
  • +
    <%= municipality.ime %> + + send + +
    +
  • + <% } %> +
+ +
+
+ + diff --git a/app/views/neighborhood.ejs b/app/views/neighborhood.ejs deleted file mode 100644 index a62de1d..0000000 --- a/app/views/neighborhood.ejs +++ /dev/null @@ -1,31 +0,0 @@ -
-

U kojem mjestu tražite nekretninu?

-
- -
-
-
    - <% for(const neighborhood of neighborhoods) { %> -
  • -
    <%= neighborhood.ime %> - - send - -
    -
  • - <% } %> -
- -
-
- - - diff --git a/index.js b/index.js index 4429737..7ca87df 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ const welcome = require('./app/controllers/welcome').getWelcome; const { getRealEstateTypes, postRealEstateTypes} = require('./app/controllers/realEstateTypes'); const { getCity, postCity } = require('./app/controllers/cities'); -const { getNeighborhood, postgNeighborhood } = require('./app/controllers/neighborhoods'); +const { getMunicipality, postMunicipality } = require('./app/controllers/municipalities'); let express = require("express"); const path = require("path"); @@ -118,8 +118,8 @@ app.post('/vrstanekretnine', postRealEstateTypes); app.get('/grad/:request_id', getCity); app.post('/grad/:request_id', postCity); -app.get('/mjesto/:request_id', getNeighborhood); -app.post('/mjesto/:request_id', postgNeighborhood); +app.get('/mjesto/:request_id', getMunicipality); +app.post('/mjesto/:request_id', postMunicipality); app.use('/assets', express.static('./app/public'));