48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
const { currentSearchRequest } = require("../helpers/url");
|
|
const { AD_CATEGORY } = require("../common/enums");
|
|
|
|
const getSize = (req, res) => {
|
|
const title = "Od koliko kvadrata tražite nekretninu ?";
|
|
const unit = " m2";
|
|
const rangeFrom = {
|
|
min: 10,
|
|
max: 250,
|
|
value: 0,
|
|
step: 10
|
|
};
|
|
|
|
const rangeTo = {
|
|
min: 10,
|
|
max: 250,
|
|
value: 50,
|
|
step: 10
|
|
};
|
|
|
|
res.render("size", { rangeFrom, rangeTo, unit, title });
|
|
};
|
|
|
|
const postSize = async (req, res) => {
|
|
const searchRequest = await currentSearchRequest(req);
|
|
|
|
const realEstateType = AD_CATEGORY[searchRequest.realEstateType];
|
|
const sizeMin = req.body.from || 0;
|
|
const sizeMax = req.body.to || 0;
|
|
//TODO: Validation, check if real estate type is valid, ...
|
|
const nextStep =
|
|
realEstateType && realEstateType.hasGardenSize ? "okucnica" : "cijena";
|
|
|
|
const nextStepPage = req.query.nextStep || nextStep;
|
|
const nextStepUrl = `/${nextStepPage}/${searchRequest.id}`;
|
|
|
|
searchRequest.sizeMin = sizeMin;
|
|
searchRequest.sizeMax = sizeMax;
|
|
await searchRequest.save();
|
|
|
|
res.redirect(nextStepUrl);
|
|
};
|
|
|
|
module.exports = {
|
|
getSize,
|
|
postSize
|
|
};
|