add new view and controller for location

This commit is contained in:
Bilal Catic
2019-09-10 07:43:18 +02:00
parent 854984029c
commit 7a6e1d5cfe
2 changed files with 118 additions and 8 deletions

View 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
};