From 026d7cded7de50c9de6fa6356c9e8126c5d5430c Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Thu, 31 Oct 2019 10:55:34 +0100 Subject: [PATCH] change price slider options for renting option --- app/common/enums.js | 33 +++++++++++++++++++++------- app/controllers/realEstateFilters.js | 16 ++++++++++++-- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/app/common/enums.js b/app/common/enums.js index c48956c..efdbe28 100644 --- a/app/common/enums.js +++ b/app/common/enums.js @@ -1,4 +1,4 @@ -const PRICE_SLIDER_OPTIONS = { +const PRICE_SLIDER_OPTIONS_SALE = { start: [50000, 85000], range: { min: [0], @@ -8,6 +8,16 @@ const PRICE_SLIDER_OPTIONS = { connect: true }; +const PRICE_SLIDER_OPTIONS_RENT = { + start: [300, 500], + range: { + min: [0], + max: [2000] + }, + step: 50, + connect: true +}; + //This will be used for Flats, Apartments, Houses const HOME_SIZE_SLIDER_OPTIONS = { start: [30, 75], @@ -84,14 +94,16 @@ const AD_CATEGORY = { id: "FLAT", title: "Stan", hasGardenSize: false, - priceSliderOptions: PRICE_SLIDER_OPTIONS, + priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS }, HOUSE: { id: "HOUSE", title: "Kuća", hasGardenSize: true, - priceSliderOptions: PRICE_SLIDER_OPTIONS, + priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS, gardenSizeSliderOptions: GARDEN_SIZE_SLIDER_OPTIONS }, @@ -99,35 +111,40 @@ const AD_CATEGORY = { id: "OFFICE", title: "Kancelarija", hasGardenSize: false, - priceSliderOptions: PRICE_SLIDER_OPTIONS, + priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS }, LAND: { id: "LAND", title: "Zemljište", hasGardenSize: false, - priceSliderOptions: PRICE_SLIDER_OPTIONS, + priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: LAND_SIZE_SLIDER_OPTIONS }, APARTMENT: { id: "APARTMENT", title: "Apartman", hasGardenSize: false, - priceSliderOptions: PRICE_SLIDER_OPTIONS, + priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS }, GARAGE: { id: "GARAGE", title: "Garaža", hasGardenSize: false, - priceSliderOptions: GARAGE_PRICE_SLIDER_OPTIONS, + priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: GARAGE_SIZE_SLIDER_OPTIONS }, COTTAGE: { id: "COTTAGE", title: "Vikendica", hasGardenSize: true, - priceSliderOptions: PRICE_SLIDER_OPTIONS, + priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS, gardenSizeSliderOptions: GARDEN_SIZE_SLIDER_OPTIONS } diff --git a/app/controllers/realEstateFilters.js b/app/controllers/realEstateFilters.js index 9e23f91..8949cc1 100644 --- a/app/controllers/realEstateFilters.js +++ b/app/controllers/realEstateFilters.js @@ -1,5 +1,5 @@ const { currentSearchRequest } = require("../helpers/url"); -const { AD_CATEGORY } = require("../common/enums"); +const { AD_CATEGORY, AD_TYPE } = require("../common/enums"); const getFilters = async (req, res) => { const searchRequest = await currentSearchRequest(req); @@ -12,6 +12,7 @@ const getFilters = async (req, res) => { const title = "Filteri za pretraživanje"; const { + adType, realEstateType, priceMin, priceMax, @@ -24,11 +25,22 @@ const getFilters = async (req, res) => { const { hasGardenSize, - priceSliderOptions, + priceSliderOptionsSale, + priceSliderOptionsRent, sizeSliderOptions, gardenSizeSliderOptions } = category; + let priceSliderOptions; + if (adType === AD_TYPE.AD_TYPE_SALE.stringId) { + priceSliderOptions = Object.assign({}, priceSliderOptionsSale); + } else if (adType === AD_TYPE.AD_TYPE_RENT.stringId) { + priceSliderOptions = Object.assign({}, priceSliderOptionsRent); + } else { + res.render("notFound", { title: " " }); + return; + } + if (priceMin || priceMax) { priceSliderOptions.start = [priceMin, priceMax]; }