52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
const { currentRERequest } = require("../helpers/url");
|
|
|
|
const getLocation = async (req, res) => {
|
|
const title = "U kojem naselju tražite nekretninu?";
|
|
const nextStep = req.query.nextStep || "/";
|
|
|
|
res.render("location", {
|
|
nextStep,
|
|
title
|
|
});
|
|
};
|
|
|
|
const postLocation = async (req, res) => {
|
|
let request = await currentRERequest(req);
|
|
|
|
const northWest = [req.body.west, req.body.north];
|
|
const northEast = [req.body.east, req.body.north];
|
|
const southEast = [req.body.east, req.body.south];
|
|
const southWest = [req.body.west, req.body.south];
|
|
|
|
request.locationInput =
|
|
req.body.locationInput && req.body.locationInput.length > 0
|
|
? req.body.locationInput
|
|
: null;
|
|
|
|
request.boundingBox = {
|
|
type: "Polygon",
|
|
coordinates: [[northWest, northEast, southEast, southWest, northWest]]
|
|
};
|
|
|
|
let locationInputData;
|
|
if (req.body.locationInputData) {
|
|
try {
|
|
locationInputData = JSON.parse(req.body.locationInputData);
|
|
} catch (e) {
|
|
locationInputData = null;
|
|
}
|
|
}
|
|
|
|
await request.save();
|
|
|
|
const nextStepPage = req.query.nextStep || "povrsina";
|
|
const nextStepUrl = `/${nextStepPage}/${request.uniqueId}`;
|
|
|
|
res.redirect(nextStepUrl);
|
|
};
|
|
|
|
module.exports = {
|
|
getLocation,
|
|
postLocation
|
|
};
|