From 864b917b4fca05df8eb95e0628ca6b4453d0878b Mon Sep 17 00:00:00 2001 From: Senad Uka Date: Tue, 30 Apr 2019 06:48:41 +0200 Subject: [PATCH] Make place selection possible --- app/controllers/grad.js | 5 +- app/controllers/mjesto.js | 3 +- app/helpers/codes.js | 70 ------------------- ...050222-add_place_to_real_estate_request.js | 18 +++++ app/models/realestaterequest.js | 1 + app/views/mjesto.ejs | 14 ++-- index.js | 5 ++ 7 files changed, 36 insertions(+), 80 deletions(-) create mode 100644 app/migrations/20190429050222-add_place_to_real_estate_request.js diff --git a/app/controllers/grad.js b/app/controllers/grad.js index 9d9c335..b3f6294 100644 --- a/app/controllers/grad.js +++ b/app/controllers/grad.js @@ -14,10 +14,11 @@ const getGrad = (req,res) => { } const postGrad = async (req, res) => { - let request = await currentRERequest(req); + const request = await currentRERequest(req); + const nextStep = req.query.nextStep || `/mjesto/${request.uniqueId}`; request.city = req.body.grad; await request.save(); - res.send("Result is " + JSON.stringify(request)); + res.redirect(nextStep) } module.exports = { diff --git a/app/controllers/mjesto.js b/app/controllers/mjesto.js index 97d7a5c..e281fb4 100644 --- a/app/controllers/mjesto.js +++ b/app/controllers/mjesto.js @@ -14,7 +14,8 @@ const getMjesto = async (req,res) => { const postMjesto = async (req, res) => { let request = await currentRERequest(req); - request.city = req.body.mjesto; + request.place = req.body.mjesto; + console.log("AAA ", req.body); await request.save(); res.send("Result is " + JSON.stringify(request)); } diff --git a/app/helpers/codes.js b/app/helpers/codes.js index 0f7c668..8cfc6be 100644 --- a/app/helpers/codes.js +++ b/app/helpers/codes.js @@ -6,11 +6,6 @@ const geographies = [ "id":"sarajevo", "olxid": "9", "mjesta":[ - { - "ime":"Mjesto", - "id":"mjesto", - "olxid":"0" - }, { "ime":"Hadžići", "id":"hadii", @@ -63,11 +58,6 @@ const geographies = [ "id":"unskosanski", "olxid": "9", "mjesta":[ - { - "ime":"Mjesto", - "id":"mjesto", - "olxid":"0" - }, { "ime":"Bihać", "id":"biha", @@ -115,11 +105,6 @@ const geographies = [ "id":"posavski", "olxid": "15", "mjesta":[ - { - "ime":"Mjesto", - "id":"mjesto", - "olxid":"0" - }, { "ime":"Domaljevac", "id":"domaljevac", @@ -147,11 +132,6 @@ const geographies = [ "id":"tuzlanski", "olxid": "15", "mjesta":[ - { - "ime":"Mjesto", - "id":"mjesto", - "olxid":"0" - }, { "ime":"Banovići", "id":"banovii", @@ -224,11 +204,6 @@ const geographies = [ "id":"zenickodobojski", "olxid": "15", "mjesta":[ - { - "ime":"Mjesto", - "id":"mjesto", - "olxid":"0" - }, { "ime":"Breza", "id":"breza", @@ -296,11 +271,6 @@ const geographies = [ "id":"bosanskopodrinjski", "olxid": "15", "mjesta":[ - { - "ime":"Mjesto", - "id":"mjesto", - "olxid":"0" - }, { "ime":"Foča", "id":"foa", @@ -323,11 +293,6 @@ const geographies = [ "id":"srednjobosanski", "olxid": "6", "mjesta":[ - { - "ime":"Mjesto", - "id":"mjesto", - "olxid":"0" - }, { "ime":"Bugojno", "id":"bugojno", @@ -395,11 +360,6 @@ const geographies = [ "id":"hercegovackoneretvanski", "olxid": "7", "mjesta":[ - { - "ime":"Mjesto", - "id":"mjesto", - "olxid":"0" - }, { "ime":"Grad Mostar", "id":"gradmostar", @@ -452,11 +412,6 @@ const geographies = [ "id":"zapadnohercegovacki", "olxid": "8", "mjesta":[ - { - "ime":"Mjesto", - "id":"mjesto", - "olxid":"0" - }, { "ime":"Grude", "id":"grude", @@ -484,11 +439,6 @@ const geographies = [ "id":"livanjski", "olxid": "10", "mjesta":[ - { - "ime":"Mjesto", - "id":"mjesto", - "olxid":"0" - }, { "ime":"Bosansko Grahovo", "id":"bosanskograhovo", @@ -526,11 +476,6 @@ const geographies = [ "id":"banjalučka", "olxid": "14", "mjesta":[ - { - "ime":"Mjesto", - "id":"mjesto", - "olxid":"0" - }, { "ime":"Banja Luka", "id":"banjaluka", @@ -643,11 +588,6 @@ const geographies = [ "id":"dobojskobijeljinska", "olxid": "15", "mjesta":[ - { - "ime":"Mjesto", - "id":"mjesto", - "olxid":"0" - }, { "ime":"Bijeljina", "id":"bijeljina", @@ -745,11 +685,6 @@ const geographies = [ "id":"sarajevskozvornicka", "olxid": "16", "mjesta":[ - { - "ime":"Mjesto", - "id":"mjesto", - "olxid":"0" - }, { "ime":"Bratunac", "id":"bratunac", @@ -872,11 +807,6 @@ const geographies = [ "id":"trebinjskofocanska", "olxid": "17", "mjesta":[ - { - "ime":"Mjesto", - "id":"mjesto", - "olxid":"0" - }, { "ime":"Berkovići", "id":"berkovii", diff --git a/app/migrations/20190429050222-add_place_to_real_estate_request.js b/app/migrations/20190429050222-add_place_to_real_estate_request.js new file mode 100644 index 0000000..3fb0b4b --- /dev/null +++ b/app/migrations/20190429050222-add_place_to_real_estate_request.js @@ -0,0 +1,18 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.addColumn( + 'RealEstateRequests', + 'place', + Sequelize.STRING + ); + }, + + down: (queryInterface, Sequelize) => { + return queryInterface.removeColumn( + 'RealEstateRequests', + 'place' + ); + } +}; diff --git a/app/models/realestaterequest.js b/app/models/realestaterequest.js index 24c3660..847b914 100644 --- a/app/models/realestaterequest.js +++ b/app/models/realestaterequest.js @@ -12,6 +12,7 @@ module.exports = (sequelize, DataTypes) => { }, email: DataTypes.STRING, city: DataTypes.STRING, + place: DataTypes.STRING, }, {}); RealEstateRequest.associate = function(models) { // associations can be defined here diff --git a/app/views/mjesto.ejs b/app/views/mjesto.ejs index ee28d77..d07e29d 100644 --- a/app/views/mjesto.ejs +++ b/app/views/mjesto.ejs @@ -1,15 +1,15 @@
-

U kojoj regiji tražite nekretninu?

+

U kojem mjestu tražite nekretninu?

-
+
    - <% for(const grad of gradovi) { %> -
  • <%= grad.ime %>send
  • + <% for(const mjesto of mjesta) { %> +
  • <%= mjesto.ime %>send
  • <% } %>
- +
@@ -17,8 +17,8 @@ $(document).ready( () => { $(".collection-item").click( (e) => { const clickedId = $(e.target).attr("id"); - $("#grad").val(clickedId); - $("#form-grad").submit(); + $("#mjesto").val(clickedId); + $("#form-mjesto").submit(); }); }); diff --git a/index.js b/index.js index a6d5443..55eeb3c 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ const dobrodosli = require('./app/controllers/dobrodosli').getDobrodosli; const { getVrstaNekretnine, postVrstaNekretnine} = require('./app/controllers/vrsta_nekretnine'); const { getGrad, postGrad } = require('./app/controllers/grad'); +const { getMjesto, postMjesto } = require('./app/controllers/mjesto'); let express = require("express"); const path = require("path"); @@ -117,6 +118,10 @@ app.post('/vrstanekretnine', postVrstaNekretnine); app.get('/grad/:request_id', getGrad); app.post('/grad/:request_id', postGrad); +app.get('/mjesto/:request_id', getMjesto); +app.post('/mjesto/:request_id', postMjesto); + + app.use('/assets', express.static('./app/public')) app.listen(port, () => console.log(`Example app listening on port ${port}!`));