2019-09-30 10:31:07 +02:00
|
|
|
const { getRealEstateById } = require("../helpers/db/realEstate");
|
2020-01-09 12:19:19 +01:00
|
|
|
const { AD_STATUS } = require("../common/enums");
|
2019-09-04 07:00:27 -07:00
|
|
|
|
2019-10-10 00:49:48 +02:00
|
|
|
const getRedirect = async (req, res) => {
|
|
|
|
|
const id = req.params.id || null;
|
|
|
|
|
let error = false;
|
|
|
|
|
let redirectUrl = undefined;
|
2020-01-09 12:19:19 +01:00
|
|
|
let vipAd = undefined;
|
2019-10-10 00:49:48 +02:00
|
|
|
if (!id) {
|
|
|
|
|
error = true;
|
|
|
|
|
} else {
|
2019-10-15 21:50:23 +02:00
|
|
|
try {
|
|
|
|
|
const realEstate = await getRealEstateById(id);
|
|
|
|
|
if (!realEstate) {
|
|
|
|
|
error = true;
|
|
|
|
|
} else {
|
|
|
|
|
redirectUrl = realEstate.url;
|
2020-01-09 12:19:19 +01:00
|
|
|
vipAd = realEstate.adStatus === AD_STATUS.STATUS_VIP;
|
2019-10-15 21:50:23 +02:00
|
|
|
}
|
|
|
|
|
} catch (e) {
|
2019-10-10 00:49:48 +02:00
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
const title = "";
|
|
|
|
|
res.render("notFound", { title });
|
|
|
|
|
} else {
|
|
|
|
|
const title = "Preusmjeravanje";
|
2020-01-09 12:19:19 +01:00
|
|
|
res.render("redirect", { title, redirectUrl, vipAd });
|
2019-10-10 00:49:48 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-04 07:00:27 -07:00
|
|
|
module.exports = {
|
2019-10-10 00:49:48 +02:00
|
|
|
getRedirect
|
2019-09-04 07:00:27 -07:00
|
|
|
};
|