2019-09-13 13:58:58 +02:00
|
|
|
const { currentSearchRequest } = require("../helpers/url");
|
2019-09-27 19:36:20 +02:00
|
|
|
const { AD_CATEGORY } = require("../common/enums");
|
2019-05-17 11:06:32 +02:00
|
|
|
|
2019-09-05 11:14:54 +02:00
|
|
|
const getSize = (req, res) => {
|
|
|
|
|
const title = "Od koliko kvadrata tražite nekretninu ?";
|
|
|
|
|
const unit = " m2";
|
2019-05-29 11:03:01 +02:00
|
|
|
const rangeFrom = {
|
2019-09-05 11:14:54 +02:00
|
|
|
min: 10,
|
|
|
|
|
max: 250,
|
|
|
|
|
value: 0,
|
|
|
|
|
step: 10
|
|
|
|
|
};
|
2019-05-29 11:03:01 +02:00
|
|
|
|
|
|
|
|
const rangeTo = {
|
2019-09-05 11:14:54 +02:00
|
|
|
min: 10,
|
|
|
|
|
max: 250,
|
|
|
|
|
value: 50,
|
|
|
|
|
step: 10
|
|
|
|
|
};
|
2019-05-29 11:03:01 +02:00
|
|
|
|
2019-09-05 11:14:54 +02:00
|
|
|
res.render("size", { rangeFrom, rangeTo, unit, title });
|
2019-05-17 11:06:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const postSize = async (req, res) => {
|
2019-09-13 13:58:58 +02:00
|
|
|
const searchRequest = await currentSearchRequest(req);
|
2019-05-22 11:36:01 +02:00
|
|
|
|
2019-09-27 19:36:20 +02:00
|
|
|
const realEstateType = AD_CATEGORY[searchRequest.realEstateType];
|
2019-09-13 13:58:58 +02:00
|
|
|
const sizeMin = req.body.from || 0;
|
|
|
|
|
const sizeMax = req.body.to || 0;
|
|
|
|
|
//TODO: Validation, check if real estate type is valid, ...
|
2019-09-05 11:14:54 +02:00
|
|
|
const nextStep =
|
|
|
|
|
realEstateType && realEstateType.hasGardenSize ? "okucnica" : "cijena";
|
2019-09-13 13:58:58 +02:00
|
|
|
|
2019-05-22 11:36:01 +02:00
|
|
|
const nextStepPage = req.query.nextStep || nextStep;
|
2019-09-13 13:58:58 +02:00
|
|
|
const nextStepUrl = `/${nextStepPage}/${searchRequest.id}`;
|
|
|
|
|
|
|
|
|
|
searchRequest.sizeMin = sizeMin;
|
|
|
|
|
searchRequest.sizeMax = sizeMax;
|
|
|
|
|
await searchRequest.save();
|
2019-05-21 15:25:28 +02:00
|
|
|
|
|
|
|
|
res.redirect(nextStepUrl);
|
2019-05-17 11:06:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
getSize,
|
|
|
|
|
postSize
|
|
|
|
|
};
|