fix redirect and unsubscribe for invalid id

This commit is contained in:
Bilal Catic
2019-10-15 21:50:23 +02:00
parent 247fe4d35c
commit 384b4a356b
2 changed files with 14 additions and 15 deletions

View File

@@ -1,16 +1,5 @@
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 id = req.params.id || null;
let error = false;
@@ -18,11 +7,15 @@ const getRedirect = async (req, res) => {
if (!id) {
error = true;
} else {
const realEstate = await getRealEstateById(id);
if (!realEstate) {
try {
const realEstate = await getRealEstateById(id);
if (!realEstate) {
error = true;
} else {
redirectUrl = realEstate.url;
}
} catch (e) {
error = true;
} else {
redirectUrl = realEstate.url;
}
}