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; let redirectUrl = undefined; if (!id) { error = true; } else { const realEstate = await getRealEstateById(id); if (!realEstate) { error = true; } else { redirectUrl = realEstate.url; } } if (error) { const title = ""; res.render("notFound", { title }); } else { const title = "Preusmjeravanje"; res.render("redirect", { title, redirectUrl }); } }; module.exports = { getRedirect };