For review view ad page.

This commit is contained in:
Naida Vatric
2020-03-14 15:34:18 +01:00
parent a36fba09eb
commit 981faeb610
5 changed files with 37 additions and 18 deletions

View File

@@ -71,6 +71,8 @@ const postPublishTypes = async (req, res) => {
realEstate.adType = adTypeStringId; realEstate.adType = adTypeStringId;
realEstate.realEstateType = selectedRealEstateType; realEstate.realEstateType = selectedRealEstateType;
//Url override
realEstate.url = `${APP_URL}/preglednekretnine/${realEstate.id}`;
await realEstate.save(); await realEstate.save();
} else { } else {
@@ -78,7 +80,7 @@ const postPublishTypes = async (req, res) => {
const newKiviOriginal = await createKiviOriginal({ const newKiviOriginal = await createKiviOriginal({
email: "" email: ""
}); });
const newKiviAdViewUrl = `${APP_URL}/preglednekretnine/${newKiviOriginal.kiviAdId}`; const newKiviAdViewUrl = `${APP_URL}/preglednekretnine/${realEstate.id}`;
const newRealEstate = await createRealEstate({ const newRealEstate = await createRealEstate({
adType: adTypeStringId, adType: adTypeStringId,

View File

@@ -1,5 +1,6 @@
const { findRealEstateByAgencyId } = require("../helpers/db/realEstate"); const { findRealEstateByAgencyId } = require("../helpers/db/realEstate");
const { currentKiviRealEstate } = require("../helpers/url"); const { findPhotosForKiviAd } = require("../helpers/db/kiviOriginalAdsPhotos");
const { currentKiviRealEstate, currentRealEstate } = require("../helpers/url");
const { const {
BASIC_BOOLEAN_PUBLISH, BASIC_BOOLEAN_PUBLISH,
@@ -13,13 +14,17 @@ const {
const { AD_CATEGORY, AD_TYPE } = require("../common/enums"); const { AD_CATEGORY, AD_TYPE } = require("../common/enums");
const getViewRealEstate = async (req, res) => { const getViewRealEstate = async (req, res) => {
//Variation if we acces to real estate previews via kiviAdId
/*
const kiviOriginal = await currentKiviRealEstate(req); const kiviOriginal = await currentKiviRealEstate(req);
if (!kiviOriginal || !kiviOriginal.kiviAdId) { if (!kiviOriginal || !kiviOriginal.kiviAdId) {
res.render("notFound", { title: " " }); res.render("notFound", { title: " " });
return; return;
} }
const realEstate = await findRealEstateByAgencyId(kiviOriginal.kiviAdId); const realEstate = await findRealEstateByAgencyId(kiviOriginal.kiviAdId); */
const realEstate = await currentRealEstate(req);
if (!realEstate || !realEstate.dataValues) { if (!realEstate || !realEstate.dataValues) {
res.render("notFound", { title: " " }); res.render("notFound", { title: " " });
@@ -32,6 +37,7 @@ const getViewRealEstate = async (req, res) => {
price, price,
area, area,
adType, adType,
agencyObjectId,
realEstateType, realEstateType,
locationLat, locationLat,
locationLong, locationLong,
@@ -153,17 +159,14 @@ const getViewRealEstate = async (req, res) => {
return forShowing(allSegmentSelectedValues[object.dbField]); return forShowing(allSegmentSelectedValues[object.dbField]);
}); });
//Placeholder array of image url-s --later to be urls from our storage bucket //Photo urls from Google storage bucket
//saved in new database table const kiviAdId = agencyObjectId;
const realEstatePhotosUrls = [ const urlGooglePrefix =
"https://cdn.pixabay.com/photo/2020/02/16/16/31/night-4854108_960_720.jpg", "https://storage.cloud.google.com/marketalarm-photos/";
"https://cdn.pixabay.com/photo/2020/02/18/14/05/building-valley-4859574_960_720.jpg", const realEstatePhotosData = await findPhotosForKiviAd(kiviAdId);
"https://cdn.pixabay.com/photo/2020/02/17/12/51/monastery-4856420_960_720.jpg", const realEstatePhotosUrls = realEstatePhotosData.map(row => {
"https://cdn.pixabay.com/photo/2020/02/20/11/11/children-4864480_960_720.jpg", return urlGooglePrefix + row.dataValues.photoUrl;
"https://cdn.pixabay.com/photo/2020/02/08/16/14/villa-4830490_960_720.jpg", });
"https://cdn.pixabay.com/photo/2020/02/19/13/26/snow-4862208_960_720.jpg",
"https://cdn.pixabay.com/photo/2020/02/18/01/16/down-4858219__340.jpg"
];
const showRealEstateType = AD_CATEGORY[realEstateType].title.toUpperCase(); const showRealEstateType = AD_CATEGORY[realEstateType].title.toUpperCase();
let showAdType = ""; let showAdType = "";

View File

@@ -39,7 +39,7 @@ const postWelcome = async (req, res) => {
const newKiviOriginal = await createKiviOriginal({ const newKiviOriginal = await createKiviOriginal({
email: "" email: ""
}); });
//Temporary url because we have cyclic id call - need to override for safety measures
const newKiviAdViewUrl = `${APP_URL}/preglednekretnine/${newKiviOriginal.kiviAdId}`; const newKiviAdViewUrl = `${APP_URL}/preglednekretnine/${newKiviOriginal.kiviAdId}`;
const newRealEstate = await createRealEstate({ const newRealEstate = await createRealEstate({

View File

@@ -12,6 +12,20 @@ const bulkUpsertKiviPhotos = async kiviPhotosData => {
} }
}; };
module.exports = { const findPhotosForKiviAd = async id => {
bulkUpsertKiviPhotos try {
return db.KiviOriginalAdsPhotos.findAll({
where: {
kiviAdId: id
}
});
} catch (error) {
console.log("kiviOriginalAdsPhotos.js", error);
return null;
}
};
module.exports = {
bulkUpsertKiviPhotos,
findPhotosForKiviAd
}; };

View File

@@ -46,7 +46,7 @@ router.post("/objavinekretninu", postPublishTypes);
router.get("/podacionekretnini/:kiviRealEstateId", getPublishInputs); router.get("/podacionekretnini/:kiviRealEstateId", getPublishInputs);
router.post("/podacionekretnini/:kiviRealEstateId", postPublishInputs); router.post("/podacionekretnini/:kiviRealEstateId", postPublishInputs);
router.get("/preglednekretnine/:kiviRealEstateId", getViewRealEstate); router.get("/preglednekretnine/:realEstateId", getViewRealEstate);
router.get("/lokacija/:searchRequestId", getLocation); router.get("/lokacija/:searchRequestId", getLocation);
router.post("/lokacija/:searchRequestId", postLocation); router.post("/lokacija/:searchRequestId", postLocation);