add new view and controller for location
This commit is contained in:
51
app/controllers/location.js
Normal file
51
app/controllers/location.js
Normal file
@@ -0,0 +1,51 @@
|
||||
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
|
||||
};
|
||||
Reference in New Issue
Block a user