change column name from 'city' to 'region'

This commit is contained in:
Bilal Catic
2019-05-17 00:33:10 +02:00
parent 42505a7089
commit 4309bc709d
7 changed files with 49 additions and 30 deletions

View File

@@ -3,7 +3,7 @@ const { getMunicipalitiesForRegion } = require('../helpers/codes');
const getMunicipality = async (req,res) => { const getMunicipality = async (req,res) => {
let request = await currentRERequest(req); let request = await currentRERequest(req);
const municipalities = getMunicipalitiesForRegion(request.city); const municipalities = getMunicipalitiesForRegion(request.region);
const nextStep = req.query.nextStep || '/'; const nextStep = req.query.nextStep || '/';
res.render('municipality', { res.render('municipality', {
nextStep, nextStep,

View File

@@ -1,26 +1,25 @@
const { currentRERequest } = require('../helpers/url'); const { currentRERequest } = require('../helpers/url');
const { regions } = require('../helpers/codes'); const { getRegions } = require('../helpers/codes');
const cities = regions(); const regions = getRegions();
const getRegion = (req,res) => {
const getCity = (req,res) => {
const nextStep = req.query.nextStep || '/'; const nextStep = req.query.nextStep || '/';
res.render('city', { res.render('region', {
nextStep, nextStep,
cities regions
}); });
} };
const postCity = async (req, res) => { const postRegion = async (req, res) => {
const request = await currentRERequest(req); const request = await currentRERequest(req);
const nextStep = req.query.nextStep || `/mjesto/${request.uniqueId}`; const nextStep = req.query.nextStep || `/mjesto/${request.uniqueId}`;
request.city = req.body.city; request.region = req.body.region;
await request.save(); await request.save();
res.redirect(nextStep) res.redirect(nextStep)
} };
module.exports = { module.exports = {
getCity, getRegion,
postCity postRegion
}; };

View File

@@ -1,4 +1,4 @@
const geographies = [ const regions = [
{ {
"ime":" Sarajevo", "ime":" Sarajevo",
"id":"sarajevo", "id":"sarajevo",
@@ -872,12 +872,12 @@ const geographies = [
} }
]; ];
const regions = () => { const getRegions = () => {
return geographies.map( (g) => ({ ime: g.ime, id: g.id, olxid: g.olxid }) ); return regions.map( (g) => ({ ime: g.ime, id: g.id, olxid: g.olxid }) );
}; };
const getMunicipalitiesForRegion = (regionId) => { const getMunicipalitiesForRegion = (regionId) => {
for (geo of geographies) { for (geo of regions) {
if(geo.id === regionId) { if(geo.id === regionId) {
return geo.mjesta; return geo.mjesta;
} }
@@ -886,6 +886,6 @@ const getMunicipalitiesForRegion = (regionId) => {
}; };
module.exports = { module.exports = {
regions, getRegions,
getMunicipalitiesForRegion getMunicipalitiesForRegion
}; };

View File

@@ -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'
);
}
};

View File

@@ -11,7 +11,7 @@ module.exports = (sequelize, DataTypes) => {
values: ['kuca','stan','vikendica','plac','poslovni_prostor','apartman','garaza'] values: ['kuca','stan','vikendica','plac','poslovni_prostor','apartman','garaza']
}, },
email: DataTypes.STRING, email: DataTypes.STRING,
city: DataTypes.STRING, region: DataTypes.STRING,
municipality: DataTypes.STRING, municipality: DataTypes.STRING,
}, {}); }, {});
RealEstateRequest.associate = function(models) { RealEstateRequest.associate = function(models) {

View File

@@ -1,13 +1,14 @@
<!--suppress HtmlUnknownAnchorTarget -->
<div class="row center-align"> <div class="row center-align">
<h2>U kojoj regiji tražite nekretninu?</h2> <h2>U kojoj regiji tražite nekretninu?</h2>
</div> </div>
<form method="POST" id="form-city"> <form method="POST" id="form-region">
<div class="row center-align"> <div class="row center-align">
<ul class="collection with-header"> <ul class="collection with-header">
<% for(const city of cities) { %> <% for(const region of regions) { %>
<li class="collection-item" > <li class="collection-item" >
<div id="<%= city.id %>" ><%= city.ime %> <div id="<%= region.id %>" ><%= region.ime %>
<a href="#!" class="secondary-content"> <a href="#!" class="secondary-content">
<i class="material-icons">send</i> <i class="material-icons">send</i>
</a> </a>
@@ -15,16 +16,16 @@
</li> </li>
<% } %> <% } %>
</ul> </ul>
<input type="hidden" name="city" id="city" /> <input type="hidden" name="region" id="region" />
</div> </div>
</form> </form>
<script> <script>
$(document).ready( () => { $(document).ready( () => {
$(".collection-item").click( (e) => { $(".collection-item").click( (e) => {
const clickedId = $(e.target).attr("id"); const clickedId = $(e.target).attr("id");
$("#city").val(clickedId); $("#region").val(clickedId);
$("#form-city").submit(); $("#form-region").submit();
}); });
}); });
</script> </script>

View File

@@ -1,6 +1,6 @@
const welcome = require('./app/controllers/welcome').getWelcome; const welcome = require('./app/controllers/welcome').getWelcome;
const { getRealEstateTypes, postRealEstateTypes} = require('./app/controllers/realEstateTypes'); 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'); const { getMunicipality, postMunicipality } = require('./app/controllers/municipalities');
let express = require("express"); let express = require("express");
@@ -115,8 +115,8 @@ app.get('/vrstanekretnine', getRealEstateTypes);
app.post('/vrstanekretnine/:request_id', postRealEstateTypes); app.post('/vrstanekretnine/:request_id', postRealEstateTypes);
app.post('/vrstanekretnine', postRealEstateTypes); app.post('/vrstanekretnine', postRealEstateTypes);
app.get('/grad/:request_id', getCity); app.get('/grad/:request_id', getRegion);
app.post('/grad/:request_id', postCity); app.post('/grad/:request_id', postRegion);
app.get('/mjesto/:request_id', getMunicipality); app.get('/mjesto/:request_id', getMunicipality);
app.post('/mjesto/:request_id', postMunicipality); app.post('/mjesto/:request_id', postMunicipality);