change column name from 'city' to 'region'
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
};
|
||||
@@ -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
|
||||
};
|
||||
|
||||
19
app/migrations/20190516222240-rename-city-column.js
Normal file
19
app/migrations/20190516222240-rename-city-column.js
Normal 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'
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
<!--suppress HtmlUnknownAnchorTarget -->
|
||||
<div class="row center-align">
|
||||
<h2>U kojoj regiji tražite nekretninu?</h2>
|
||||
</div>
|
||||
|
||||
<form method="POST" id="form-city">
|
||||
<form method="POST" id="form-region">
|
||||
<div class="row center-align">
|
||||
<ul class="collection with-header">
|
||||
<% for(const city of cities) { %>
|
||||
<li class="collection-item" >
|
||||
<div id="<%= city.id %>" ><%= city.ime %>
|
||||
<% for(const region of regions) { %>
|
||||
<li class="collection-item" >
|
||||
<div id="<%= region.id %>" ><%= region.ime %>
|
||||
<a href="#!" class="secondary-content">
|
||||
<i class="material-icons">send</i>
|
||||
</a>
|
||||
@@ -15,16 +16,16 @@
|
||||
</li>
|
||||
<% } %>
|
||||
</ul>
|
||||
<input type="hidden" name="city" id="city" />
|
||||
<input type="hidden" name="region" id="region" />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
$(document).ready( () => {
|
||||
$(".collection-item").click( (e) => {
|
||||
const clickedId = $(e.target).attr("id");
|
||||
$("#city").val(clickedId);
|
||||
$("#form-city").submit();
|
||||
const clickedId = $(e.target).attr("id");
|
||||
$("#region").val(clickedId);
|
||||
$("#form-region").submit();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
6
index.js
6
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);
|
||||
|
||||
Reference in New Issue
Block a user