Files
old-web/app/controllers/gardenSizes.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

const { currentSearchRequest } = require("../helpers/url");
const { AD_CATEGORY } = require("../common/enums");
2019-05-17 11:12:24 +02:00
2019-09-05 11:14:54 +02:00
const getGardenSize = (req, res) => {
const title = "Koliko okućnice tražite ?";
2019-09-05 11:14:54 +02:00
const unit = " m2";
const rangeFrom = {
2019-09-05 11:14:54 +02:00
min: 10,
max: 3000,
value: 0,
step: 10
};
const rangeTo = {
2019-09-05 11:14:54 +02:00
min: 10,
max: 3000,
value: 100,
step: 10
};
2019-09-05 11:14:54 +02:00
res.render("gardenSize", { rangeFrom, rangeTo, unit, title });
2019-05-17 11:12:24 +02:00
};
const postGardenSize = async (req, res) => {
const searchRequest = await currentSearchRequest(req);
2019-09-05 11:14:54 +02:00
const nextStepPage = req.query.nextStep || "cijena";
const nextStepUrl = `/${nextStepPage}/${searchRequest.id}`;
const realEstateType = AD_CATEGORY[searchRequest.realEstateType];
if (realEstateType && realEstateType.hasGardenSize) {
const gardenSizeMin = req.body.from || 0;
const gardenSizeMax = req.body.to || 0;
//TODO: Validate input
searchRequest.gardenSizeMin = gardenSizeMin;
searchRequest.gardenSizeMax = gardenSizeMax;
await searchRequest.save();
}
res.redirect(nextStepUrl);
2019-05-17 11:12:24 +02:00
};
module.exports = {
getGardenSize,
postGardenSize
};