Added delete ability.
This commit is contained in:
@@ -1,21 +1,32 @@
|
|||||||
const { currentSearchRequest } = require("../helpers/url");
|
const { currentKiviRealEstate } = require("../helpers/url");
|
||||||
|
const { findRealEstateByAgencyId } = require("../helpers/db/realEstate");
|
||||||
|
|
||||||
const getDeletePublishedAd = async (req, res) => {
|
const getDeletePublishedAd = async (req, res) => {
|
||||||
const title = "Uspješno ste izbrisali svoj oglas iz baze.";
|
const title = "Uspješno ste izbrisali svoj oglas iz baze.";
|
||||||
|
|
||||||
const searchRequest = await currentSearchRequest(req);
|
const kiviOriginal = await currentKiviRealEstate(req);
|
||||||
|
|
||||||
if (!searchRequest || !searchRequest.dataValues) {
|
if (!kiviOriginal || !kiviOriginal.kiviAdId) {
|
||||||
|
res.render("notFound", { title: " " });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const realEstate = await findRealEstateByAgencyId(kiviOriginal.kiviAdId);
|
||||||
|
|
||||||
|
if (!realEstate || !realEstate.dataValues) {
|
||||||
res.render("notFound", { title: " " });
|
res.render("notFound", { title: " " });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
searchRequest.subscribed = false;
|
realEstate.deleted = true;
|
||||||
searchRequest.deletedEmail = searchRequest.email;
|
realEstate.deletedAt = Date.now();
|
||||||
searchRequest.email = "";
|
|
||||||
await searchRequest.save();
|
|
||||||
|
|
||||||
res.render("unsubscribe", { nextStep: "/vrstanekretnine", title });
|
kiviOriginal.email = "";
|
||||||
|
|
||||||
|
await realEstate.save();
|
||||||
|
|
||||||
|
await kiviOriginal.save();
|
||||||
|
|
||||||
|
res.render("deleteRealEstate", { nextStep: "/", title });
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@@ -350,6 +350,13 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
//Query only for real estated that are not deleted
|
||||||
|
query.deleted = {
|
||||||
|
[Op.eq]: false
|
||||||
|
};
|
||||||
|
queryIncludeIncomplete.deleted = {
|
||||||
|
[Op.eq]: false
|
||||||
|
};
|
||||||
|
|
||||||
const order = [["updatedAt", "desc"]];
|
const order = [["updatedAt", "desc"]];
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
up: (queryInterface, Sequelize) => {
|
||||||
|
return Promise.all([
|
||||||
|
queryInterface.addColumn("RealEstates", "deleted", {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false
|
||||||
|
}),
|
||||||
|
queryInterface.addColumn("RealEstates", "deletedAt", {
|
||||||
|
type: Sequelize.DATE
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
|
||||||
|
down: (queryInterface, Sequelize) => {
|
||||||
|
return Promise.all([
|
||||||
|
queryInterface.removeColumn("RealEstates", "deleted"),
|
||||||
|
queryInterface.removeColumn("RealEstates", "deletedAt")
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -85,7 +85,9 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
utilityConnection: DataTypes.BOOLEAN,
|
utilityConnection: DataTypes.BOOLEAN,
|
||||||
distanceToRiver: DataTypes.INTEGER,
|
distanceToRiver: DataTypes.INTEGER,
|
||||||
numberOfViewsAgency: DataTypes.INTEGER,
|
numberOfViewsAgency: DataTypes.INTEGER,
|
||||||
numberOfViewsKivi: DataTypes.INTEGER
|
numberOfViewsKivi: DataTypes.INTEGER,
|
||||||
|
deleted: DataTypes.BOOLEAN,
|
||||||
|
deletedAt: DataTypes.DATE
|
||||||
});
|
});
|
||||||
|
|
||||||
return RealEstate;
|
return RealEstate;
|
||||||
|
|||||||
@@ -9,11 +9,16 @@ const { MAX_REAL_ESTATES_IN_FIRST_EMAIL } = require("../config/appConfig");
|
|||||||
const { EMAIL_FREQUENCY } = require("../common/enums");
|
const { EMAIL_FREQUENCY } = require("../common/enums");
|
||||||
|
|
||||||
const matchRealEstates = async realEstates => {
|
const matchRealEstates = async realEstates => {
|
||||||
if (Array.isArray(realEstates)) {
|
//Filter deleted real estates
|
||||||
|
const filteredRealEstates = realEstates.filter(
|
||||||
|
realEstate => realEstate.deleted === false
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Array.isArray(filteredRealEstates)) {
|
||||||
const asyncMatchActions = [];
|
const asyncMatchActions = [];
|
||||||
const matches = {};
|
const matches = {};
|
||||||
const matchingRecords = [];
|
const matchingRecords = [];
|
||||||
for (const realEstate of realEstates) {
|
for (const realEstate of filteredRealEstates) {
|
||||||
const searchRequestsPromise = findSearchRequestsForRealEstate(realEstate);
|
const searchRequestsPromise = findSearchRequestsForRealEstate(realEstate);
|
||||||
asyncMatchActions.push(searchRequestsPromise);
|
asyncMatchActions.push(searchRequestsPromise);
|
||||||
|
|
||||||
|
|||||||
12
app/views/deleteRealEstate.ejs
Normal file
12
app/views/deleteRealEstate.ejs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<!-- -->
|
||||||
|
<br><br>
|
||||||
|
<div class="row center-align">
|
||||||
|
<img src="../assets/images/logo.svg" alt="kivi logo" width="160">
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col s6 push-s3">
|
||||||
|
<a href="<%= nextStep %>" class="welcome-center-button waves-effect waves-light btn">
|
||||||
|
Početna stranica
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user