2019-09-05 11:14:54 +02:00
|
|
|
const { currentRERequest } = require("../helpers/url");
|
|
|
|
|
const { getRegionName, getMunicipalityName } = require("../helpers/codes");
|
|
|
|
|
const {
|
|
|
|
|
realEstateTypes,
|
|
|
|
|
sizes,
|
|
|
|
|
gardenSizes,
|
|
|
|
|
prices,
|
|
|
|
|
getEnumTypeTitle,
|
|
|
|
|
getRealEstateTypeEnum
|
|
|
|
|
} = require("../helpers/enums");
|
2019-05-19 12:29:55 +02:00
|
|
|
|
2019-09-05 11:14:54 +02:00
|
|
|
const getQueryReview = async (req, res) => {
|
|
|
|
|
const title = "Da li je ovo to što ste tražili ?";
|
2019-05-19 12:29:55 +02:00
|
|
|
const request = await currentRERequest(req);
|
|
|
|
|
const nextStep = req.query.nextStep;
|
|
|
|
|
|
|
|
|
|
if (!request || !request.dataValues) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-05 11:14:54 +02:00
|
|
|
const {
|
|
|
|
|
realEstateType,
|
|
|
|
|
region,
|
|
|
|
|
municipality,
|
|
|
|
|
sizeMin,
|
|
|
|
|
sizeMax,
|
|
|
|
|
gardenSizeMin,
|
|
|
|
|
gardenSizeMax,
|
|
|
|
|
priceMin,
|
|
|
|
|
priceMax
|
|
|
|
|
} = request.dataValues;
|
2019-05-19 12:29:55 +02:00
|
|
|
|
2019-05-22 11:36:01 +02:00
|
|
|
const realEstateTypeObject = getRealEstateTypeEnum(realEstateType);
|
2019-09-05 11:14:54 +02:00
|
|
|
const enableGardenSizeEdit = realEstateTypeObject
|
|
|
|
|
? realEstateTypeObject.hasGardenSize
|
|
|
|
|
: false;
|
2019-05-22 11:36:01 +02:00
|
|
|
|
2019-09-05 11:14:54 +02:00
|
|
|
const realEstateTypeTitle = realEstateType
|
|
|
|
|
? getEnumTypeTitle(realEstateTypes, realEstateType)
|
|
|
|
|
: null;
|
2019-05-19 12:29:55 +02:00
|
|
|
const regionName = region ? getRegionName(region) : null;
|
2019-09-05 11:14:54 +02:00
|
|
|
const municipalityName =
|
|
|
|
|
region && municipality ? getMunicipalityName(region, municipality) : null;
|
2019-05-30 10:43:47 +02:00
|
|
|
const sizeTitle = sizeMin ? sizeMin + "-" + sizeMax + " m2" : null;
|
2019-09-05 11:14:54 +02:00
|
|
|
const gardenSizeTitle = gardenSizeMin
|
|
|
|
|
? gardenSizeMin + "-" + gardenSizeMax + " m2"
|
|
|
|
|
: null;
|
|
|
|
|
const priceTitle = priceMin ? priceMin + "-" + priceMax + " KM" : null;
|
2019-05-19 12:29:55 +02:00
|
|
|
|
2019-09-05 11:14:54 +02:00
|
|
|
const uniqueId = request.dataValues.uniqueId
|
|
|
|
|
? request.dataValues.uniqueId
|
|
|
|
|
: "";
|
2019-05-19 12:29:55 +02:00
|
|
|
|
|
|
|
|
const queryData = [
|
|
|
|
|
{
|
2019-09-05 11:14:54 +02:00
|
|
|
id: "realEstateType",
|
2019-05-19 12:29:55 +02:00
|
|
|
title: realEstateTypeTitle,
|
2019-09-05 11:14:54 +02:00
|
|
|
url: `/vrstanekretnine/${uniqueId}?nextStep=pregled`
|
2019-05-19 12:29:55 +02:00
|
|
|
},
|
|
|
|
|
{
|
2019-09-05 11:14:54 +02:00
|
|
|
id: "region",
|
2019-05-19 12:29:55 +02:00
|
|
|
title: regionName,
|
2019-09-05 11:14:54 +02:00
|
|
|
url: `/grad/${uniqueId}?nextStep=mjesto`
|
2019-05-19 12:29:55 +02:00
|
|
|
},
|
|
|
|
|
{
|
2019-09-05 11:14:54 +02:00
|
|
|
id: "municipality",
|
2019-05-19 12:29:55 +02:00
|
|
|
title: municipalityName,
|
2019-09-05 11:14:54 +02:00
|
|
|
url: `/mjesto/${uniqueId}?nextStep=pregled`
|
2019-05-19 12:29:55 +02:00
|
|
|
},
|
|
|
|
|
{
|
2019-09-05 11:14:54 +02:00
|
|
|
id: "size",
|
2019-05-19 12:29:55 +02:00
|
|
|
title: sizeTitle,
|
2019-09-05 11:14:54 +02:00
|
|
|
url: `/povrsina/${uniqueId}?nextStep=pregled`
|
2019-05-19 12:29:55 +02:00
|
|
|
},
|
|
|
|
|
{
|
2019-09-05 11:14:54 +02:00
|
|
|
id: "gardenSize",
|
2019-05-19 12:29:55 +02:00
|
|
|
title: gardenSizeTitle,
|
2019-09-05 11:14:54 +02:00
|
|
|
url: enableGardenSizeEdit ? `/okucnica/${uniqueId}?nextStep=pregled` : ""
|
2019-05-19 12:29:55 +02:00
|
|
|
},
|
|
|
|
|
{
|
2019-09-05 11:14:54 +02:00
|
|
|
id: "price",
|
2019-05-19 12:29:55 +02:00
|
|
|
title: priceTitle,
|
2019-05-21 15:25:28 +02:00
|
|
|
url: `/cijena/${uniqueId}?nextStep=pregled`
|
2019-05-19 12:29:55 +02:00
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
2019-09-05 11:14:54 +02:00
|
|
|
res.render("queryReview", {
|
2019-05-19 12:29:55 +02:00
|
|
|
nextStep,
|
|
|
|
|
queryData,
|
2019-07-11 14:25:38 +02:00
|
|
|
title
|
2019-05-19 12:29:55 +02:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const postQueryReview = async (req, res) => {
|
|
|
|
|
const request = await currentRERequest(req);
|
2019-05-19 13:34:44 +02:00
|
|
|
const nextStep = req.query.nextStep || `/posalji/${request.uniqueId}`;
|
|
|
|
|
|
|
|
|
|
res.redirect(nextStep);
|
2019-05-19 12:29:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
getQueryReview,
|
|
|
|
|
postQueryReview
|
|
|
|
|
};
|