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.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,

View File

@@ -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 = "";

View File

@@ -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({

View File

@@ -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
};

View File

@@ -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);