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

52 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-09-05 11:14:54 +02:00
const { currentRERequest } = require("../helpers/url");
2019-05-17 10:49:13 +02:00
const getLocation = async (req, res) => {
2019-09-05 11:14:54 +02:00
const title = "U kojem naselju tražite nekretninu?";
const nextStep = req.query.nextStep || "/";
res.render("location", {
2019-09-05 11:14:54 +02:00
nextStep,
title
});
2019-05-17 10:49:13 +02:00
};
const postLocation = async (req, res) => {
2019-09-05 11:14:54 +02:00
let request = await currentRERequest(req);
2019-09-05 11:14:54 +02:00
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 = {
2019-09-05 11:14:54 +02:00
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;
}
}
2019-09-05 11:14:54 +02:00
await request.save();
const nextStepPage = req.query.nextStep || "povrsina";
const nextStepUrl = `/${nextStepPage}/${request.uniqueId}`;
res.redirect(nextStepUrl);
2019-05-17 10:49:13 +02:00
};
module.exports = {
getLocation,
postLocation
2019-09-05 11:14:54 +02:00
};