Added real estate ad edit ability
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
const { findRealEstateByAgencyId } = require("../helpers/db/realEstate");
|
const { findRealEstateByAgencyId } = require("../helpers/db/realEstate");
|
||||||
const {
|
const {
|
||||||
bulkUpsertKiviPhotos,
|
bulkUpsertKiviPhotos,
|
||||||
findPhotosForKiviAd
|
findPhotosForKiviAd,
|
||||||
|
deleteUrlPhotosAfterUpdate
|
||||||
} = require("../helpers/db/kiviOriginalAdsPhotos");
|
} = require("../helpers/db/kiviOriginalAdsPhotos");
|
||||||
const { currentKiviRealEstate } = require("../helpers/url");
|
const { currentKiviRealEstate } = require("../helpers/url");
|
||||||
const {
|
const {
|
||||||
@@ -202,8 +203,8 @@ const getPublishInputs = async (req, res) => {
|
|||||||
additionalInputValues,
|
additionalInputValues,
|
||||||
validate: validate,
|
validate: validate,
|
||||||
email,
|
email,
|
||||||
locationLat, //: locationLat || 0,
|
locationLat: locationLat || 0,
|
||||||
locationLong, //: locationLong || 0,
|
locationLong: locationLong || 0,
|
||||||
editingRealEstate,
|
editingRealEstate,
|
||||||
realEstatePhotosUrls
|
realEstatePhotosUrls
|
||||||
});
|
});
|
||||||
@@ -225,7 +226,7 @@ const postPublishInputs = async (req, res) => {
|
|||||||
|
|
||||||
const editingRealEstate = req.body.editingRealEstate === "true";
|
const editingRealEstate = req.body.editingRealEstate === "true";
|
||||||
|
|
||||||
console.log("Editing real estate:", editingRealEstate);
|
// console.log("Editing real estate:", editingRealEstate);
|
||||||
|
|
||||||
const nextStepPage = editingRealEstate
|
const nextStepPage = editingRealEstate
|
||||||
? req.query.nextStep || "/uspjesnaizmjena"
|
? req.query.nextStep || "/uspjesnaizmjena"
|
||||||
@@ -296,6 +297,10 @@ const postPublishInputs = async (req, res) => {
|
|||||||
//Image urls are stored in new table
|
//Image urls are stored in new table
|
||||||
const imageUrls =
|
const imageUrls =
|
||||||
req.body.imageUrls.split("|").filter(url => url !== "") || [];
|
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 => {
|
const imageUrlsData = imageUrls.map(url => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const db = require("../../models/index");
|
const db = require("../../models/index");
|
||||||
|
|
||||||
const sequelize = require("sequelize");
|
const sequelize = require("sequelize");
|
||||||
|
const Op = sequelize.Op;
|
||||||
|
|
||||||
const bulkUpsertKiviPhotos = async kiviPhotosData => {
|
const bulkUpsertKiviPhotos = async kiviPhotosData => {
|
||||||
try {
|
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 = {
|
module.exports = {
|
||||||
bulkUpsertKiviPhotos,
|
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: {
|
kiviAdId: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
|
unique: "uniqueKiviAdIdPhoto",
|
||||||
references: {
|
references: {
|
||||||
model: "KiviOriginal",
|
model: "KiviOriginal",
|
||||||
key: "kiviAdId"
|
key: "kiviAdId"
|
||||||
@@ -20,7 +21,8 @@ module.exports = (sequalize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
photoUrl: {
|
photoUrl: {
|
||||||
type: DataTypes.TEXT,
|
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
|
//Move map and marker to already selected position if in editing mode
|
||||||
if( editingRealEstate===true) {
|
if( editingRealEstate===true) {
|
||||||
console.log('Editujem mapu!');
|
//console.log('Editujem mapu!');
|
||||||
setMarkerToLocation(map, editingRealEstate);
|
setMarkerToLocation(map, editingRealEstate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
<br>
|
<br>
|
||||||
<% if(editingRealEstate) { %>
|
|
||||||
<div>Editujem oglas!</div>
|
|
||||||
<% } %>
|
|
||||||
|
|
||||||
<form id="publishForm" method="POST" novalidate >
|
<form id="publishForm" method="POST" novalidate >
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|||||||
Reference in New Issue
Block a user