adapt price and query review steps for new DB design

This commit is contained in:
Bilal Catic
2019-09-13 14:17:46 +02:00
parent ff68e96f4f
commit e26c2b6e8d
3 changed files with 35 additions and 35 deletions

View File

@@ -1,4 +1,4 @@
const { currentRERequest } = require("../helpers/url"); const { currentSearchRequest } = require("../helpers/url");
const getPrice = (req, res) => { const getPrice = (req, res) => {
const title = "Koja Vam okvirna cijena odgovara ?"; const title = "Koja Vam okvirna cijena odgovara ?";
@@ -22,14 +22,17 @@ const getPrice = (req, res) => {
}; };
const postPrice = async (req, res) => { const postPrice = async (req, res) => {
const request = await currentRERequest(req); const searchRequest = await currentSearchRequest(req);
const nextStepPage = req.query.nextStep || "pregled"; const nextStepPage = req.query.nextStep || "pregled";
const nextStepUrl = `/${nextStepPage}/${request.uniqueId}`; const nextStepUrl = `/${nextStepPage}/${searchRequest.id}`;
const priceMin = req.body.from || 0;
const priceMax = req.body.to || 0;
//TODO: price validation
request.priceMin = req.body.from; searchRequest.priceMin = priceMin;
request.priceMax = req.body.to; searchRequest.priceMax = priceMax;
await request.save(); await searchRequest.save();
res.redirect(nextStepUrl); res.redirect(nextStepUrl);
}; };

View File

@@ -1,4 +1,4 @@
const { currentRERequest } = require("../helpers/url"); const { currentSearchRequest } = require("../helpers/url");
const { const {
realEstateTypes, realEstateTypes,
getEnumTypeTitle, getEnumTypeTitle,
@@ -7,23 +7,23 @@ const {
const getQueryReview = async (req, res) => { const getQueryReview = async (req, res) => {
const title = "Da li je ovo to što ste tražili ?"; const title = "Da li je ovo to što ste tražili ?";
const request = await currentRERequest(req); const searchRequest = await currentSearchRequest(req);
const nextStep = req.query.nextStep; const nextStep = req.query.nextStep;
if (!request || !request.dataValues) { if (!searchRequest || !searchRequest.dataValues) {
return null; return null;
} }
const { const {
id,
realEstateType, realEstateType,
sizeMin, sizeMin,
sizeMax, sizeMax,
gardenSizeMin, gardenSizeMin,
gardenSizeMax, gardenSizeMax,
priceMin, priceMin,
priceMax, priceMax
locationInput } = searchRequest.dataValues;
} = request.dataValues;
const realEstateTypeObject = getRealEstateTypeEnum(realEstateType); const realEstateTypeObject = getRealEstateTypeEnum(realEstateType);
const enableGardenSizeEdit = realEstateTypeObject const enableGardenSizeEdit = realEstateTypeObject
@@ -32,58 +32,55 @@ const getQueryReview = async (req, res) => {
const realEstateTypeTitle = realEstateType const realEstateTypeTitle = realEstateType
? getEnumTypeTitle(realEstateTypes, realEstateType) ? getEnumTypeTitle(realEstateTypes, realEstateType)
: null; : "-";
const locationTitle = locationInput ? locationInput : "-"; const locationTitle = "Location description - PLACEHOLDER";
const sizeTitle = sizeMin && sizeMax ? `${sizeMin} - ${sizeMax} m2` : "-";
const gardenSizeTitle =
enableGardenSizeEdit && gardenSizeMin && gardenSizeMax
? `${gardenSizeMin} - ${gardenSizeMax} m2`
: "-";
const priceTitle =
priceMin && priceMax ? `${priceMin} - ${priceMax} KM` : "-";
const sizeTitle = sizeMin ? sizeMin + "-" + sizeMax + " m2" : null; const queryReviewData = [
const gardenSizeTitle = gardenSizeMin
? gardenSizeMin + "-" + gardenSizeMax + " m2"
: null;
const priceTitle = priceMin ? priceMin + "-" + priceMax + " KM" : null;
const uniqueId = request.dataValues.uniqueId
? request.dataValues.uniqueId
: "";
const queryData = [
{ {
id: "realEstateType", id: "realEstateType",
title: realEstateTypeTitle, title: realEstateTypeTitle,
url: `/vrstanekretnine/${uniqueId}?nextStep=pregled` url: `/vrstanekretnine/${id}?nextStep=pregled`
}, },
{ {
id: "location", id: "location",
title: locationTitle, title: locationTitle,
url: `/lokacija/${uniqueId}?nextStep=pregled` url: `/lokacija/${id}?nextStep=pregled`
}, },
{ {
id: "size", id: "size",
title: sizeTitle, title: sizeTitle,
url: `/povrsina/${uniqueId}?nextStep=pregled` url: `/povrsina/${id}?nextStep=pregled`
}, },
{ {
id: "gardenSize", id: "gardenSize",
title: gardenSizeTitle, title: gardenSizeTitle,
url: enableGardenSizeEdit ? `/okucnica/${uniqueId}?nextStep=pregled` : "" url: enableGardenSizeEdit ? `/okucnica/${id}?nextStep=pregled` : ""
}, },
{ {
id: "price", id: "price",
title: priceTitle, title: priceTitle,
url: `/cijena/${uniqueId}?nextStep=pregled` url: `/cijena/${id}?nextStep=pregled`
} }
]; ];
res.render("queryReview", { res.render("queryReview", {
nextStep, nextStep,
queryData, queryReviewData,
title title
}); });
}; };
const postQueryReview = async (req, res) => { const postQueryReview = async (req, res) => {
const request = await currentRERequest(req); const searchRequest = await currentSearchRequest(req);
const nextStep = req.query.nextStep || `/posalji/${request.uniqueId}`; const nextStep = req.query.nextStep || `/posalji/${searchRequest.id}`;
res.redirect(nextStep); res.redirect(nextStep);
}; };

View File

@@ -1,10 +1,10 @@
<!--suppress HtmlUnknownAnchorTarget --> <!--suppress HtmlUnknownAnchorTarget -->
<% include partials/navBar %> <% include partials/navBar %>
<form method="POST" id="form-queryreview"> <form method="POST" id="form-queryreview">
<div class="row center-align"> <div class="row center-align">
<ul class="collection with-header"> <ul class="collection with-header">
<% for(const stepData of queryData) { %> <% for(const stepData of queryReviewData) { %>
<li class="collection-item" > <li class="collection-item" >
<div id="<%= stepData.id %>" ><%= stepData.title || '-' %> <div id="<%= stepData.id %>" ><%= stepData.title || '-' %>
<a href="<%= stepData.url %>" class="secondary-content"> <a href="<%= stepData.url %>" class="secondary-content">