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