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