Removing existing photos wip.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
const { findRealEstateByAgencyId } = require("../helpers/db/realEstate");
|
||||
const { bulkUpsertKiviPhotos } = require("../helpers/db/kiviOriginalAdsPhotos");
|
||||
const {
|
||||
bulkUpsertKiviPhotos,
|
||||
findPhotosForKiviAd
|
||||
} = require("../helpers/db/kiviOriginalAdsPhotos");
|
||||
const { currentKiviRealEstate } = require("../helpers/url");
|
||||
const {
|
||||
notifyForNewRealEstates,
|
||||
@@ -27,7 +30,9 @@ const {
|
||||
const getPublishInputs = async (req, res) => {
|
||||
const kiviOriginal = await currentKiviRealEstate(req);
|
||||
|
||||
const realEstate = await findRealEstateByAgencyId(kiviOriginal.kiviAdId);
|
||||
const realEstate = await findRealEstateByAgencyId(
|
||||
kiviOriginal.dataValues.kiviAdId
|
||||
);
|
||||
|
||||
if (!realEstate || !realEstate.dataValues) {
|
||||
res.render("notFound", { title: " " });
|
||||
@@ -83,13 +88,27 @@ const getPublishInputs = async (req, res) => {
|
||||
longDescription
|
||||
} = realEstate;
|
||||
|
||||
const { email } = kiviOriginal;
|
||||
const email = kiviOriginal.dataValues.email;
|
||||
//If email is not empty - has string value, then proces of publishing has been conducted alredy
|
||||
//That means user is editing existing real estate ad not publishing new one
|
||||
let editingRealEstate = false;
|
||||
if (email) {
|
||||
editingRealEstate = true;
|
||||
}
|
||||
//If we are editing real estate ad we need to fetch and show images on server
|
||||
const urlGooglePrefix =
|
||||
"https://storage.cloud.google.com/marketalarm-photos/";
|
||||
let realEstatePhotosUrls = [];
|
||||
if (editingRealEstate) {
|
||||
const realEstatePhotosData = await findPhotosForKiviAd(
|
||||
kiviOriginal.dataValues.kiviAdId
|
||||
);
|
||||
realEstatePhotosData.map(row => {
|
||||
realEstatePhotosUrls.push(urlGooglePrefix + row.dataValues.photoUrl);
|
||||
});
|
||||
} else {
|
||||
realEstatePhotosUrls.push(false);
|
||||
}
|
||||
|
||||
const category = AD_CATEGORY[realEstateType] || AD_CATEGORY.FLAT;
|
||||
|
||||
@@ -185,7 +204,8 @@ const getPublishInputs = async (req, res) => {
|
||||
email,
|
||||
locationLat: locationLat || 0,
|
||||
locationLong: locationLong || 0,
|
||||
editingRealEstate
|
||||
editingRealEstate,
|
||||
realEstatePhotosUrls
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user