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

@@ -1,28 +1,42 @@
const { currentRERequest } = require("../helpers/url");
const getNeighborhood = async (req, res) => {
const getLocation = async (req, res) => {
const title = "U kojem naselju tražite nekretninu?";
const municipality = req.params.municipality;
const nextStep = req.query.nextStep || "/";
res.render("neighborhoodMap", {
res.render("location", {
nextStep,
municipality,
title
});
};
const postNeighborhood = async (req, res) => {
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.bounding_box = {
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";
@@ -32,6 +46,6 @@ const postNeighborhood = async (req, res) => {
};
module.exports = {
getNeighborhood,
postNeighborhood
getLocation,
postLocation
};