From acdeca94dff274088bb15fc31e1067b0195d5d0e Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Tue, 15 Oct 2019 18:51:19 +0200 Subject: [PATCH] redirect to Not Found page when search request param is missing from URL --- app/controllers/location.js | 5 +++++ app/controllers/realEstateFilters.js | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/controllers/location.js b/app/controllers/location.js index 43f6c29..e0bd4ca 100644 --- a/app/controllers/location.js +++ b/app/controllers/location.js @@ -13,6 +13,11 @@ const getLocation = async (req, res) => { const postLocation = async (req, res) => { let searchRequest = await currentSearchRequest(req); + if (!searchRequest || !searchRequest.dataValues) { + res.render("notFound", { title: " " }); + return; + } + const northWest = [req.body.west, req.body.north]; const northEast = [req.body.east, req.body.north]; const southEast = [req.body.east, req.body.south]; diff --git a/app/controllers/realEstateFilters.js b/app/controllers/realEstateFilters.js index 4630352..c29b2c4 100644 --- a/app/controllers/realEstateFilters.js +++ b/app/controllers/realEstateFilters.js @@ -3,6 +3,12 @@ const { AD_CATEGORY } = require("../common/enums"); const getFilters = async (req, res) => { const searchRequest = await currentSearchRequest(req); + + if (!searchRequest || !searchRequest.dataValues) { + res.render("notFound", { title: " " }); + return; + } + const title = "Filteri za pretraživanje"; const { @@ -47,6 +53,11 @@ const getFilters = async (req, res) => { const postFilters = async (req, res) => { const searchRequest = await currentSearchRequest(req); + if (!searchRequest || !searchRequest.dataValues) { + res.render("notFound", { title: " " }); + return; + } + const nextStepPage = req.query.nextStep || "pregled"; const nextStepUrl = `/${nextStepPage}/${searchRequest.id}`;