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

74 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-05-19 12:29:55 +02:00
const { currentRERequest } = require('../helpers/url');
const { getRegionName, getMunicipalityName } = require('../helpers/codes');
const { realEstateTypes, sizes, gardenSizes, prices, getEnumTypeTitle } = require('../helpers/enums');
const getQueryReview = async (req,res) => {
const request = await currentRERequest(req);
const nextStep = req.query.nextStep;
if (!request || !request.dataValues) {
return null;
}
const { realEstateType, region, municipality, size, gardenSize, price } = request.dataValues;
const realEstateTypeTitle = realEstateType ? getEnumTypeTitle(realEstateTypes, realEstateType) : null;
const regionName = region ? getRegionName(region) : null;
const municipalityName = (region && municipality) ? getMunicipalityName(region, municipality) : null;
const sizeTitle = size ? getEnumTypeTitle(sizes, size) : null;
const gardenSizeTitle = gardenSize ? getEnumTypeTitle(gardenSizes, gardenSize) : null;
const priceTitle = price ? getEnumTypeTitle(prices, price) : null;
const uniqueId = request.dataValues.uniqueId ? request.dataValues.uniqueId : '';
const queryData = [
{
id: 'realEstateType',
title: realEstateTypeTitle,
url: `/vrstanekretnine/${uniqueId}?nextStep=pregled`,
2019-05-19 12:29:55 +02:00
},
{
id: 'region',
title: regionName,
url: `/grad/${uniqueId}?nextStep=mjesto`,
2019-05-19 12:29:55 +02:00
},
{
id: 'municipality',
title: municipalityName,
url: `/mjesto/${uniqueId}?nextStep=pregled`,
2019-05-19 12:29:55 +02:00
},
{
id: 'size',
title: sizeTitle,
url: `/povrsina/${uniqueId}?nextStep=pregled`,
2019-05-19 12:29:55 +02:00
},
{
id: 'gardenSize',
title: gardenSizeTitle,
url: `/okucnica/${uniqueId}?nextStep=pregled`,
2019-05-19 12:29:55 +02:00
},
{
id: 'price',
title: priceTitle,
url: `/cijena/${uniqueId}?nextStep=pregled`
2019-05-19 12:29:55 +02:00
}
];
res.render('queryReview', {
nextStep,
queryData,
});
};
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
};