diff --git a/app/controllers/publishRealEstateTypes.js b/app/controllers/publishRealEstateTypes.js index b49b415..1373b04 100644 --- a/app/controllers/publishRealEstateTypes.js +++ b/app/controllers/publishRealEstateTypes.js @@ -71,6 +71,8 @@ const postPublishTypes = async (req, res) => { realEstate.adType = adTypeStringId; realEstate.realEstateType = selectedRealEstateType; + //Url override + realEstate.url = `${APP_URL}/preglednekretnine/${realEstate.id}`; await realEstate.save(); } else { @@ -78,7 +80,7 @@ const postPublishTypes = async (req, res) => { const newKiviOriginal = await createKiviOriginal({ email: "" }); - const newKiviAdViewUrl = `${APP_URL}/preglednekretnine/${newKiviOriginal.kiviAdId}`; + const newKiviAdViewUrl = `${APP_URL}/preglednekretnine/${realEstate.id}`; const newRealEstate = await createRealEstate({ adType: adTypeStringId, diff --git a/app/controllers/viewRealEstate.js b/app/controllers/viewRealEstate.js index f2dfd78..e541a0b 100644 --- a/app/controllers/viewRealEstate.js +++ b/app/controllers/viewRealEstate.js @@ -1,5 +1,6 @@ const { findRealEstateByAgencyId } = require("../helpers/db/realEstate"); -const { currentKiviRealEstate } = require("../helpers/url"); +const { findPhotosForKiviAd } = require("../helpers/db/kiviOriginalAdsPhotos"); +const { currentKiviRealEstate, currentRealEstate } = require("../helpers/url"); const { BASIC_BOOLEAN_PUBLISH, @@ -13,13 +14,17 @@ const { const { AD_CATEGORY, AD_TYPE } = require("../common/enums"); const getViewRealEstate = async (req, res) => { + //Variation if we acces to real estate previews via kiviAdId + /* const kiviOriginal = await currentKiviRealEstate(req); if (!kiviOriginal || !kiviOriginal.kiviAdId) { res.render("notFound", { title: " " }); return; } - const realEstate = await findRealEstateByAgencyId(kiviOriginal.kiviAdId); + const realEstate = await findRealEstateByAgencyId(kiviOriginal.kiviAdId); */ + + const realEstate = await currentRealEstate(req); if (!realEstate || !realEstate.dataValues) { res.render("notFound", { title: " " }); @@ -32,6 +37,7 @@ const getViewRealEstate = async (req, res) => { price, area, adType, + agencyObjectId, realEstateType, locationLat, locationLong, @@ -153,17 +159,14 @@ const getViewRealEstate = async (req, res) => { return forShowing(allSegmentSelectedValues[object.dbField]); }); - //Placeholder array of image url-s --later to be urls from our storage bucket - //saved in new database table - const realEstatePhotosUrls = [ - "https://cdn.pixabay.com/photo/2020/02/16/16/31/night-4854108_960_720.jpg", - "https://cdn.pixabay.com/photo/2020/02/18/14/05/building-valley-4859574_960_720.jpg", - "https://cdn.pixabay.com/photo/2020/02/17/12/51/monastery-4856420_960_720.jpg", - "https://cdn.pixabay.com/photo/2020/02/20/11/11/children-4864480_960_720.jpg", - "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" - ]; + //Photo urls from Google storage bucket + const kiviAdId = agencyObjectId; + const urlGooglePrefix = + "https://storage.cloud.google.com/marketalarm-photos/"; + const realEstatePhotosData = await findPhotosForKiviAd(kiviAdId); + const realEstatePhotosUrls = realEstatePhotosData.map(row => { + return urlGooglePrefix + row.dataValues.photoUrl; + }); const showRealEstateType = AD_CATEGORY[realEstateType].title.toUpperCase(); let showAdType = ""; diff --git a/app/controllers/welcome.js b/app/controllers/welcome.js index 30d793c..654172b 100644 --- a/app/controllers/welcome.js +++ b/app/controllers/welcome.js @@ -39,7 +39,7 @@ const postWelcome = async (req, res) => { const newKiviOriginal = await createKiviOriginal({ email: "" }); - + //Temporary url because we have cyclic id call - need to override for safety measures const newKiviAdViewUrl = `${APP_URL}/preglednekretnine/${newKiviOriginal.kiviAdId}`; const newRealEstate = await createRealEstate({ diff --git a/app/helpers/db/kiviOriginalAdsPhotos.js b/app/helpers/db/kiviOriginalAdsPhotos.js index 5533897..07cfc59 100644 --- a/app/helpers/db/kiviOriginalAdsPhotos.js +++ b/app/helpers/db/kiviOriginalAdsPhotos.js @@ -12,6 +12,20 @@ const bulkUpsertKiviPhotos = async kiviPhotosData => { } }; -module.exports = { - bulkUpsertKiviPhotos +const findPhotosForKiviAd = async id => { + try { + return db.KiviOriginalAdsPhotos.findAll({ + where: { + kiviAdId: id + } + }); + } catch (error) { + console.log("kiviOriginalAdsPhotos.js", error); + return null; + } +}; + +module.exports = { + bulkUpsertKiviPhotos, + findPhotosForKiviAd }; diff --git a/app/routes/index.js b/app/routes/index.js index e09c544..b294210 100644 --- a/app/routes/index.js +++ b/app/routes/index.js @@ -46,7 +46,7 @@ router.post("/objavinekretninu", postPublishTypes); router.get("/podacionekretnini/:kiviRealEstateId", getPublishInputs); router.post("/podacionekretnini/:kiviRealEstateId", postPublishInputs); -router.get("/preglednekretnine/:kiviRealEstateId", getViewRealEstate); +router.get("/preglednekretnine/:realEstateId", getViewRealEstate); router.get("/lokacija/:searchRequestId", getLocation); router.post("/lokacija/:searchRequestId", postLocation);