Added real estate ad edit ability

This commit is contained in:
Naida Vatric
2020-03-25 16:33:21 +01:00
parent 3fa9804ca6
commit 11848cc0bb
6 changed files with 52 additions and 10 deletions

View File

@@ -1,7 +1,8 @@
const { findRealEstateByAgencyId } = require("../helpers/db/realEstate");
const {
bulkUpsertKiviPhotos,
findPhotosForKiviAd
findPhotosForKiviAd,
deleteUrlPhotosAfterUpdate
} = require("../helpers/db/kiviOriginalAdsPhotos");
const { currentKiviRealEstate } = require("../helpers/url");
const {
@@ -202,8 +203,8 @@ const getPublishInputs = async (req, res) => {
additionalInputValues,
validate: validate,
email,
locationLat, //: locationLat || 0,
locationLong, //: locationLong || 0,
locationLat: locationLat || 0,
locationLong: locationLong || 0,
editingRealEstate,
realEstatePhotosUrls
});
@@ -225,7 +226,7 @@ const postPublishInputs = async (req, res) => {
const editingRealEstate = req.body.editingRealEstate === "true";
console.log("Editing real estate:", editingRealEstate);
// console.log("Editing real estate:", editingRealEstate);
const nextStepPage = editingRealEstate
? req.query.nextStep || "/uspjesnaizmjena"
@@ -296,6 +297,10 @@ const postPublishInputs = async (req, res) => {
//Image urls are stored in new table
const imageUrls =
req.body.imageUrls.split("|").filter(url => url !== "") || [];
//If we are in editing mode we need to "delete" photos that are not longer associated with real estate ad
if (editingRealEstate) {
await deleteUrlPhotosAfterUpdate(imageUrls);
}
const imageUrlsData = imageUrls.map(url => {
return {