diff --git a/app/controllers/gardenSizes.js b/app/controllers/gardenSizes.js index 84408a5..23b7be9 100644 --- a/app/controllers/gardenSizes.js +++ b/app/controllers/gardenSizes.js @@ -3,17 +3,17 @@ const { getRealEstateTypeEnum } = require('../helpers/enums'); const getGardenSize = (req,res) => { const rangeFrom = { - min : 0, + min : 10, max : 3000, value : 0, - step : 100 + step : 10 } const rangeTo = { - min : 0, + min : 10, max : 3000, value : 100, - step : 100 + step : 10 } res.render('gardenSize', { rangeFrom, rangeTo }); }; @@ -26,8 +26,8 @@ const postGardenSize = async (req, res) => { const realEstateType = getRealEstateTypeEnum(request.realEstateType); if (realEstateType && realEstateType.hasGardenSize) { - request.gardenSize = req.body.from; - request.gardenSizeRange = req.body.to; + request.gardenSizeMin = req.body.from; + request.gardenSizeMax = req.body.to; await request.save(); } diff --git a/app/controllers/prices.js b/app/controllers/prices.js index e65455f..b6a1270 100644 --- a/app/controllers/prices.js +++ b/app/controllers/prices.js @@ -2,14 +2,14 @@ const { currentRERequest } = require('../helpers/url'); const getPrice = (req,res) => { const rangeFrom = { - min : 0, + min : 1000, max : 250000, value : 0, step : 1000 } const rangeTo = { - min : 0, + min : 1000, max : 250000, value : 50000, step : 1000 @@ -25,8 +25,8 @@ const postPrice = async (req, res) => { const nextStepPage = req.query.nextStep || 'pregled'; const nextStepUrl = `/${nextStepPage}/${request.uniqueId}`; - request.price = req.body.from; - request.priceRange = req.body.to; + request.priceMin = req.body.from; + request.priceMax = req.body.to; await request.save(); res.redirect(nextStepUrl); diff --git a/app/controllers/queryReview.js b/app/controllers/queryReview.js index a54b95a..3ec1240 100644 --- a/app/controllers/queryReview.js +++ b/app/controllers/queryReview.js @@ -14,12 +14,12 @@ const getQueryReview = async (req,res) => { realEstateType, region, municipality, - size, - sizeRange, - gardenSize, - gardenSizeRange, - price, - priceRange } = request.dataValues; + sizeMin, + sizeMax, + gardenSizeMin, + gardenSizeMax, + priceMin, + priceMax } = request.dataValues; const realEstateTypeObject = getRealEstateTypeEnum(realEstateType); const enableGardenSizeEdit = realEstateTypeObject ? realEstateTypeObject.hasGardenSize : false; @@ -27,9 +27,9 @@ const getQueryReview = async (req,res) => { const realEstateTypeTitle = realEstateType ? getEnumTypeTitle(realEstateTypes, realEstateType) : null; const regionName = region ? getRegionName(region) : null; const municipalityName = (region && municipality) ? getMunicipalityName(region, municipality) : null; - const sizeTitle = size ? size + "-" + sizeRange + " m2" : null; - const gardenSizeTitle = gardenSize ? gardenSize + "-" + gardenSizeRange + " m2" : null; - const priceTitle = price ? price + "-" + priceRange + " KM" : null; + const sizeTitle = sizeMin ? sizeMin + "-" + sizeMax + " m2" : null; + const gardenSizeTitle = gardenSizeMin ? gardenSizeMin + "-" + gardenSizeMax + " m2" : null; + const priceTitle = priceMin ? priceMin + "-" + priceMax + " KM" : null; const uniqueId = request.dataValues.uniqueId ? request.dataValues.uniqueId : ''; diff --git a/app/controllers/querySubmit.js b/app/controllers/querySubmit.js index 4ed6863..27d1771 100644 --- a/app/controllers/querySubmit.js +++ b/app/controllers/querySubmit.js @@ -1,7 +1,7 @@ const { currentRERequest } = require('../helpers/url'); const { isValidEmail } = require('../helpers/email'); -const getQuerySubmit = async (req,res) => { +const getQuerySubmit = async (req, res) => { const nextStep = req.query.nextStep; const error = req.query.error; @@ -16,14 +16,30 @@ const postQuerySubmit = async (req, res) => { const nextStep = req.query.nextStep || '/ponovo'; const emailInput = req.body.email; + const emailConfirmInput = req.body.confirm; + let error = "Greška ! Unesite validan email"; - if (isValidEmail(emailInput)){ - request.email = req.body.email; - await request.save(); - res.redirect(nextStep); - } else { - res.redirect('?error=1'); + if (!isValidEmail(emailInput) || !isValidEmail(emailConfirmInput)) { + + error = "Greška ! Unesite validan email"; + res.render('querySubmit', { + error + }); + return; } + + if (emailInput !== emailConfirmInput) { + + error = "Greška ! Unešeni emailovi nisu isti"; + res.render('querySubmit', { + error + }); + return; + } + + request.email = req.body.email; + await request.save(); + res.redirect(nextStep); }; module.exports = { diff --git a/app/controllers/sizes.js b/app/controllers/sizes.js index d536553..63325e0 100644 --- a/app/controllers/sizes.js +++ b/app/controllers/sizes.js @@ -3,14 +3,14 @@ const { sizes, getRealEstateTypeEnum } = require('../helpers/enums'); const getSize = (req,res) => { const rangeFrom = { - min : 0, + min : 10, max : 250, value : 0, step : 10 } const rangeTo = { - min : 0, + min : 10, max : 250, value : 50, step : 10 @@ -27,8 +27,8 @@ const postSize = async (req, res) => { const nextStep = realEstateType && realEstateType.hasGardenSize ? 'okucnica' : 'cijena'; const nextStepPage = req.query.nextStep || nextStep; const nextStepUrl = `/${nextStepPage}/${request.uniqueId}`; - request.size = req.body.from; - request.sizeRange = req.body.to; + request.sizeMin = req.body.from; + request.sizeMax = req.body.to; await request.save(); res.redirect(nextStepUrl); diff --git a/app/migrations/20190530101945-range-fields.js b/app/migrations/20190530101945-range-fields.js new file mode 100644 index 0000000..caad42c --- /dev/null +++ b/app/migrations/20190530101945-range-fields.js @@ -0,0 +1,63 @@ +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.sequelize.transaction((t) => { + return Promise.all([ + queryInterface.removeColumn('RealEstateRequests', 'sizeRange', { transaction: t }), + queryInterface.removeColumn('RealEstateRequests', 'gardenSizeRange', { transaction: t }), + queryInterface.removeColumn('RealEstateRequests', 'priceRange', { transaction: t }), + queryInterface.removeColumn('RealEstateRequests', 'size', { transaction: t }), + queryInterface.removeColumn('RealEstateRequests', 'gardenSize', { transaction: t }), + queryInterface.removeColumn('RealEstateRequests', 'price', { transaction: t }), + queryInterface.addColumn('RealEstateRequests', 'gardenSizeMin', { + type: Sequelize.INTEGER, + }, { transaction: t }), + queryInterface.addColumn('RealEstateRequests', 'gardenSizeMax', { + type: Sequelize.INTEGER, + }, { transaction: t }), + queryInterface.addColumn('RealEstateRequests', 'sizeMin', { + type: Sequelize.INTEGER + }, { transaction: t }), + queryInterface.addColumn('RealEstateRequests', 'sizeMax', { + type: Sequelize.INTEGER, + }, { transaction: t }), + queryInterface.addColumn('RealEstateRequests', 'priceMin', { + type: Sequelize.INTEGER, + }, { transaction: t }), + queryInterface.addColumn('RealEstateRequests', 'priceMax', { + type: Sequelize.INTEGER + }, { transaction: t }) + ]) + }) + }, + + down: (queryInterface, Sequelize) => { + return queryInterface.sequelize.transaction((t) => { + return Promise.all([ + queryInterface.removeColumn('RealEstateRequests', 'gardenSizeMin', { transaction: t }), + queryInterface.removeColumn('RealEstateRequests', 'gardenSizeMax', { transaction: t }), + queryInterface.removeColumn('RealEstateRequests', 'sizeMin', { transaction: t }), + queryInterface.removeColumn('RealEstateRequests', 'sizeMax', { transaction: t }), + queryInterface.removeColumn('RealEstateRequests', 'priceMin', { transaction: t }), + queryInterface.removeColumn('RealEstateRequests', 'priceMin', { transaction: t }), + queryInterface.addColumn('RealEstateRequests', 'priceMax', { + type: Sequelize.STRING + }, { transaction: t }), + queryInterface.addColumn('RealEstateRequests', 'gardenSizeRange', { + type: Sequelize.STRING, + }, { transaction: t }), + queryInterface.addColumn('RealEstateRequests', 'priceRange', { + type: Sequelize.STRING, + }, { transaction: t }), + queryInterface.addColumn('RealEstateRequests', 'size', { + type: Sequelize.STRING + }, { transaction: t }), + queryInterface.addColumn('RealEstateRequests', 'gardenSize', { + type: Sequelize.STRING, + }, { transaction: t }), + queryInterface.addColumn('RealEstateRequests', 'price', { + type: Sequelize.STRING, + }, { transaction: t }) + ]) + }) + } +}; \ No newline at end of file diff --git a/app/models/realestaterequest.js b/app/models/realestaterequest.js index 228bbc6..9147209 100644 --- a/app/models/realestaterequest.js +++ b/app/models/realestaterequest.js @@ -12,12 +12,12 @@ module.exports = (sequelize, DataTypes) => { email: DataTypes.STRING, region: DataTypes.STRING, municipality: DataTypes.STRING, - size: DataTypes.STRING, - sizeRange: DataTypes.STRING, - gardenSize: DataTypes.STRING, - gardenSizeRange: DataTypes.STRING, - price: DataTypes.STRING, - priceRange: DataTypes.STRING, + sizeMin: DataTypes.INTEGER, + sizeMax: DataTypes.INTEGER, + gardenSizeMin: DataTypes.INTEGER, + gardenSizeMax: DataTypes.INTEGER, + priceMin: DataTypes.INTEGER, + priceMax: DataTypes.INTEGER, bounding_box: DataTypes.GEOMETRY('POINT', 4326) }, {}); RealEstateRequest.associate = function(models) { diff --git a/app/views/neighborhoodMap.ejs b/app/views/neighborhoodMap.ejs index 76c580d..86a0cab 100644 --- a/app/views/neighborhoodMap.ejs +++ b/app/views/neighborhoodMap.ejs @@ -73,10 +73,10 @@ $("#btnsubmit").click(() => { var bounds = map.getBounds(); - $("#north").val(bounds.na.l); - $("#south").val(bounds.na.j); - $("#east").val(bounds.ia.l); - $("#west").val(bounds.ia.j); + $("#north").val(map.getBounds().getNorthEast().lat()); + $("#south").val(map.getBounds().getSouthWest().lat()); + $("#east").val(map.getBounds().getNorthEast().lng()); + $("#west").val(map.getBounds().getSouthWest().lng()); $("#form-map-output").submit(); }); diff --git a/app/views/querySubmit.ejs b/app/views/querySubmit.ejs index 5612ce4..ded8ac6 100644 --- a/app/views/querySubmit.ejs +++ b/app/views/querySubmit.ejs @@ -9,13 +9,25 @@ - <% if (error) {%> -
-
-
Greška ! Unesite ispravan email
-
+ +
+
+
<%= error %>
- <%}%> +
+ +
+
+ +
+
+ +
+
+
+
+
+