fix redirect and unsubscribe for invalid id
This commit is contained in:
@@ -1,16 +1,5 @@
|
|||||||
const { getRealEstateById } = require("../helpers/db/realEstate");
|
const { getRealEstateById } = require("../helpers/db/realEstate");
|
||||||
|
|
||||||
const redirect = async (req, res) => {
|
|
||||||
const id = req.params["id"];
|
|
||||||
const marketAlert = await getRealEstateById(id);
|
|
||||||
if (marketAlert) {
|
|
||||||
res.redirect(marketAlert.url);
|
|
||||||
} else {
|
|
||||||
res.send("Not found");
|
|
||||||
res.end();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getRedirect = async (req, res) => {
|
const getRedirect = async (req, res) => {
|
||||||
const id = req.params.id || null;
|
const id = req.params.id || null;
|
||||||
let error = false;
|
let error = false;
|
||||||
@@ -18,11 +7,15 @@ const getRedirect = async (req, res) => {
|
|||||||
if (!id) {
|
if (!id) {
|
||||||
error = true;
|
error = true;
|
||||||
} else {
|
} else {
|
||||||
const realEstate = await getRealEstateById(id);
|
try {
|
||||||
if (!realEstate) {
|
const realEstate = await getRealEstateById(id);
|
||||||
|
if (!realEstate) {
|
||||||
|
error = true;
|
||||||
|
} else {
|
||||||
|
redirectUrl = realEstate.url;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
error = true;
|
error = true;
|
||||||
} else {
|
|
||||||
redirectUrl = realEstate.url;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ const { currentSearchRequest } = require("../helpers/url");
|
|||||||
const getUnsubscribe = async (req, res) => {
|
const getUnsubscribe = async (req, res) => {
|
||||||
const title = "Uspješno ste se odjavili";
|
const title = "Uspješno ste se odjavili";
|
||||||
const searchRequest = await currentSearchRequest(req);
|
const searchRequest = await currentSearchRequest(req);
|
||||||
|
|
||||||
|
if (!searchRequest || !searchRequest.dataValues) {
|
||||||
|
res.render("notFound", { title: " " });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
searchRequest.subscribed = false;
|
searchRequest.subscribed = false;
|
||||||
await searchRequest.save();
|
await searchRequest.save();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user