Added real estate ad edit ability
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"use strict";
|
||||
const db = require("../../models/index");
|
||||
|
||||
const sequelize = require("sequelize");
|
||||
const Op = sequelize.Op;
|
||||
|
||||
const bulkUpsertKiviPhotos = async kiviPhotosData => {
|
||||
try {
|
||||
@@ -25,7 +27,25 @@ const findPhotosForKiviAd = async id => {
|
||||
}
|
||||
};
|
||||
|
||||
const deleteUrlPhotosAfterUpdate = async photoUrlsToKeep => {
|
||||
//We delete all urls that are not in "newly changed - edited" photo urls array
|
||||
const deleteQuery = {
|
||||
photoUrl: {
|
||||
[Op.notIn]: photoUrlsToKeep
|
||||
}
|
||||
};
|
||||
try {
|
||||
return db.KiviOriginalAdsPhotos.destroy({
|
||||
where: deleteQuery
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("kiviOriginalAdsPhotos.js", error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
bulkUpsertKiviPhotos,
|
||||
findPhotosForKiviAd
|
||||
findPhotosForKiviAd,
|
||||
deleteUrlPhotosAfterUpdate
|
||||
};
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) =>
|
||||
queryInterface.addConstraint(
|
||||
"KiviOriginalAdsPhotos",
|
||||
["kiviAdId", "photoUrl"],
|
||||
{
|
||||
type: "unique",
|
||||
name: "uniqueKiviAdIdPhoto"
|
||||
}
|
||||
),
|
||||
down: queryInterface =>
|
||||
queryInterface.removeConstraint(
|
||||
"KiviOriginalAdsPhotos",
|
||||
"uniqueKiviAdIdPhoto"
|
||||
)
|
||||
};
|
||||
@@ -13,6 +13,7 @@ module.exports = (sequalize, DataTypes) => {
|
||||
kiviAdId: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false,
|
||||
unique: "uniqueKiviAdIdPhoto",
|
||||
references: {
|
||||
model: "KiviOriginal",
|
||||
key: "kiviAdId"
|
||||
@@ -20,7 +21,8 @@ module.exports = (sequalize, DataTypes) => {
|
||||
},
|
||||
photoUrl: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false
|
||||
allowNull: false,
|
||||
unique: "uniqueKiviAdIdPhoto"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -107,7 +107,7 @@
|
||||
|
||||
//Move map and marker to already selected position if in editing mode
|
||||
if( editingRealEstate===true) {
|
||||
console.log('Editujem mapu!');
|
||||
//console.log('Editujem mapu!');
|
||||
setMarkerToLocation(map, editingRealEstate);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
<br>
|
||||
<% if(editingRealEstate) { %>
|
||||
<div>Editujem oglas!</div>
|
||||
<% } %>
|
||||
|
||||
<form id="publishForm" method="POST" novalidate >
|
||||
<div class="row">
|
||||
|
||||
Reference in New Issue
Block a user