2019-09-13 14:17:46 +02:00
|
|
|
const { currentSearchRequest } = require("../helpers/url");
|
2019-05-17 11:32:41 +02:00
|
|
|
|
2019-09-05 11:14:54 +02:00
|
|
|
const getPrice = (req, res) => {
|
|
|
|
|
const title = "Koja Vam okvirna cijena odgovara ?";
|
2019-06-03 10:34:59 +02:00
|
|
|
|
2019-09-05 11:14:54 +02:00
|
|
|
const unit = " KM";
|
2019-05-29 11:03:01 +02:00
|
|
|
const rangeFrom = {
|
2019-09-05 11:14:54 +02:00
|
|
|
min: 1000,
|
|
|
|
|
max: 250000,
|
|
|
|
|
value: 0,
|
|
|
|
|
step: 1000
|
|
|
|
|
};
|
2019-05-29 11:03:01 +02:00
|
|
|
|
|
|
|
|
const rangeTo = {
|
2019-09-05 11:14:54 +02:00
|
|
|
min: 1000,
|
|
|
|
|
max: 250000,
|
|
|
|
|
value: 50000,
|
|
|
|
|
step: 1000
|
|
|
|
|
};
|
2019-05-29 11:03:01 +02:00
|
|
|
|
2019-09-05 11:14:54 +02:00
|
|
|
res.render("price", { rangeFrom, rangeTo, unit, title });
|
2019-05-17 11:32:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const postPrice = async (req, res) => {
|
2019-09-13 14:17:46 +02:00
|
|
|
const searchRequest = await currentSearchRequest(req);
|
2019-05-21 15:25:28 +02:00
|
|
|
|
2019-09-05 11:14:54 +02:00
|
|
|
const nextStepPage = req.query.nextStep || "pregled";
|
2019-09-13 14:17:46 +02:00
|
|
|
const nextStepUrl = `/${nextStepPage}/${searchRequest.id}`;
|
|
|
|
|
const priceMin = req.body.from || 0;
|
|
|
|
|
const priceMax = req.body.to || 0;
|
|
|
|
|
//TODO: price validation
|
|
|
|
|
|
|
|
|
|
searchRequest.priceMin = priceMin;
|
|
|
|
|
searchRequest.priceMax = priceMax;
|
|
|
|
|
await searchRequest.save();
|
2019-05-21 15:25:28 +02:00
|
|
|
|
|
|
|
|
res.redirect(nextStepUrl);
|
2019-05-17 11:32:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
getPrice,
|
|
|
|
|
postPrice
|
|
|
|
|
};
|