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

48 lines
1.3 KiB
JavaScript
Raw Normal View History

const { currentSearchRequest } = require("../helpers/url");
const { createSearchRequest } = require("../helpers/db/searchRequest");
const { AD_CATEGORY } = require("../common/enums");
2019-04-14 06:01:37 +02:00
2019-09-05 11:14:54 +02:00
const getRealEstateTypes = (req, res) => {
const title = "Koju nekretninu tražite?";
const realEstateTypes = Object.keys(AD_CATEGORY)
.map(category => AD_CATEGORY[category])
.filter(category => category.title);
2019-09-05 11:14:54 +02:00
res.render("realEstateType", { realEstateTypes, title });
2019-05-16 19:40:26 +02:00
};
2019-03-26 05:06:15 +01:00
const postRealEstateTypes = async (req, res) => {
const searchRequest = await currentSearchRequest(req);
//TODO: check if selected real estate type is valid
const selectedRealEstateType = req.body.realEstateType || null;
const nextStepPage = req.query.nextStep || "lokacija";
let nextStepUrl = "";
if (searchRequest && searchRequest.id) {
nextStepUrl = `/${nextStepPage}/${searchRequest.id}`;
searchRequest.realEstateType = selectedRealEstateType;
await searchRequest.save();
} else {
try {
const newSearchRequest = await createSearchRequest({
realEstateType: selectedRealEstateType
2019-09-05 11:14:54 +02:00
});
nextStepUrl = `/${nextStepPage}/${newSearchRequest.id}`;
} catch (error) {
console.log(error);
nextStepUrl = `/`;
}
}
res.redirect(nextStepUrl);
2019-05-16 19:40:26 +02:00
};
2019-04-16 06:27:11 +02:00
2019-05-16 19:40:26 +02:00
module.exports = {
2019-05-15 15:27:10 +02:00
getRealEstateTypes,
postRealEstateTypes
2019-03-26 05:06:15 +01:00
};