City is now saved
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
const db = require('../models/index');
|
||||||
|
const { currentRERequest } = require('../helpers/url');
|
||||||
|
|
||||||
|
const gradovi = [
|
||||||
|
{"ime":" Sarajevo","id":"sarajevo"},
|
||||||
|
{"ime":" Unsko-sanski","id":"unskosanski"},
|
||||||
|
{"ime":" Posavski","id":"posavski"},
|
||||||
|
{"ime":" Tuzlanski","id":"tuzlanski"},
|
||||||
|
{"ime":" Zeničko-dobojski","id":"zenickodobojski"},
|
||||||
|
{"ime":" Bosansko-podrinjski","id":"bosanskopodrinjski"},
|
||||||
|
{"ime":" Srednjobosanski","id":"srednjobosanski"},
|
||||||
|
{"ime":" Hercegovačko-neretvanski","id":"hercegovackoneretvanski"},
|
||||||
|
{"ime":" Zapadno-hercegovački","id":"zapadnohercegovacki"},
|
||||||
|
{"ime":" Livanjski","id":"livanjski"},
|
||||||
|
{"ime":" Banjalučka","id":"banjalučka"},
|
||||||
|
{"ime":" Dobojsko-Bijeljinska","id":"dobojskobijeljinska"},
|
||||||
|
{"ime":" Sarajevsko-Zvornička","id":"sarajevskozvornicka"},
|
||||||
|
{"ime":" Trebinjsko-Fočanska","id":"trebinjskofocanska"},
|
||||||
|
{"ime":"Distrikt Brčko","id":"distriktbrcko"},
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
const getGrad = (req,res) => {
|
||||||
|
const nextStep = req.query.nextStep || '/';
|
||||||
|
res.render('grad', {
|
||||||
|
nextStep,
|
||||||
|
gradovi
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const postGrad = async (req, res) => {
|
||||||
|
let request = await currentRERequest(req);
|
||||||
|
request.city = req.body.grad;
|
||||||
|
await request.save();
|
||||||
|
res.send("Result is " + JSON.stringify(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getGrad,
|
||||||
|
postGrad
|
||||||
|
};
|
||||||
|
|||||||
@@ -8,17 +8,21 @@ const vrsteNekretnina = [
|
|||||||
|
|
||||||
|
|
||||||
const getVrstaNekretnine = (req,res) => {
|
const getVrstaNekretnine = (req,res) => {
|
||||||
|
const nextStep = req.query.nextStep;
|
||||||
res.render('vrsta_nekretnine', {
|
res.render('vrsta_nekretnine', {
|
||||||
nextStep: '/',
|
nextStep,
|
||||||
vrste: vrsteNekretnina
|
vrste: vrsteNekretnina
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const postVrstaNekretnine = (req, res) => {
|
const postVrstaNekretnine = (req, res) => {
|
||||||
|
let nextStep = req.query.nextStep;
|
||||||
|
|
||||||
db.RealEstateRequest.create({
|
db.RealEstateRequest.create({
|
||||||
realEstateType: req.body.vrsta
|
realEstateType: req.body.vrsta
|
||||||
}).then( (result) => {
|
}).then( (result) => {
|
||||||
res.send("Result is " + JSON.stringify(result));
|
nextStep = nextStep || `/grad/${result.uniqueId}`;
|
||||||
|
res.redirect(nextStep);
|
||||||
}).catch( (e) => {
|
}).catch( (e) => {
|
||||||
res.send(e);
|
res.send(e);
|
||||||
});
|
});
|
||||||
|
|||||||
14
app/helpers/url.js
Normal file
14
app/helpers/url.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
const db = require('../models/index');
|
||||||
|
|
||||||
|
const currentRERequest = async (req) => {
|
||||||
|
const uniqueId = req.params['request_id'];
|
||||||
|
if(!uniqueId) return null;
|
||||||
|
|
||||||
|
const request = await db.RealEstateRequest.findOne({ where: {uniqueId} });
|
||||||
|
console.log("Request ", request);
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
currentRERequest
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
up: (queryInterface, Sequelize) => {
|
||||||
|
return queryInterface.addColumn(
|
||||||
|
'RealEstateRequests',
|
||||||
|
'city',
|
||||||
|
Sequelize.STRING
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
down: (queryInterface, Sequelize) => {
|
||||||
|
return queryInterface.removeColumn(
|
||||||
|
'RealEstateRequests',
|
||||||
|
'city'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -10,7 +10,8 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
type: DataTypes.ENUM,
|
type: DataTypes.ENUM,
|
||||||
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,
|
||||||
}, {});
|
}, {});
|
||||||
RealEstateRequest.associate = function(models) {
|
RealEstateRequest.associate = function(models) {
|
||||||
// associations can be defined here
|
// associations can be defined here
|
||||||
|
|||||||
25
app/views/grad.ejs
Normal file
25
app/views/grad.ejs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<div class="row center-align">
|
||||||
|
<h2>U kojoj regiji tražite nekretninu?</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form method="POST" id="form-grad">
|
||||||
|
<div class="row center-align">
|
||||||
|
<ul class="collection with-header">
|
||||||
|
<% for(const grad of gradovi) { %>
|
||||||
|
<li class="collection-item" > <div id="<%= grad.id %>" ><%= grad.ime %><a href="#!" class="secondary-content"><i class="material-icons">send</i></a></div></li>
|
||||||
|
<% } %>
|
||||||
|
</ul>
|
||||||
|
<input type="hidden" name="grad" id="grad" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$(document).ready( () => {
|
||||||
|
$(".collection-item").click( (e) => {
|
||||||
|
const clickedId = $(e.target).attr("id");
|
||||||
|
$("#grad").val(clickedId);
|
||||||
|
$("#form-grad").submit();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
11
index.js
11
index.js
@@ -1,6 +1,6 @@
|
|||||||
const dobrodosli = require('./app/controllers/dobrodosli').getDobrodosli;
|
const dobrodosli = require('./app/controllers/dobrodosli').getDobrodosli;
|
||||||
const getVrstaNekretnine = require('./app/controllers/vrsta_nekretnine').getVrstaNekretnine;
|
const { getVrstaNekretnine, postVrstaNekretnine} = require('./app/controllers/vrsta_nekretnine');
|
||||||
const postVrstaNekretnine = require('./app/controllers/vrsta_nekretnine').postVrstaNekretnine;
|
const { getGrad, postGrad } = require('./app/controllers/grad');
|
||||||
|
|
||||||
let express = require("express");
|
let express = require("express");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
@@ -108,8 +108,15 @@ app.post("/api/payforalert", function(request, response) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get('/', dobrodosli);
|
app.get('/', dobrodosli);
|
||||||
|
app.get('/vrstanekretnine/:request_id', getVrstaNekretnine);
|
||||||
app.get('/vrstanekretnine', getVrstaNekretnine);
|
app.get('/vrstanekretnine', getVrstaNekretnine);
|
||||||
|
|
||||||
|
app.post('/vrstanekretnine/:request_id', postVrstaNekretnine);
|
||||||
app.post('/vrstanekretnine', postVrstaNekretnine);
|
app.post('/vrstanekretnine', postVrstaNekretnine);
|
||||||
|
|
||||||
|
app.get('/grad/:request_id', getGrad);
|
||||||
|
app.post('/grad/:request_id', postGrad);
|
||||||
|
|
||||||
app.use('/assets', express.static('./app/public'))
|
app.use('/assets', express.static('./app/public'))
|
||||||
|
|
||||||
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
|
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
|
||||||
|
|||||||
Reference in New Issue
Block a user