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 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: " " });
|
||||
return;
|
||||
}
|
||||
|
||||
searchRequest.subscribed = false;
|
||||
searchRequest.deletedEmail = searchRequest.email;
|
||||
searchRequest.email = "";
|
||||
await searchRequest.save();
|
||||
realEstate.deleted = true;
|
||||
realEstate.deletedAt = Date.now();
|
||||
|
||||
res.render("unsubscribe", { nextStep: "/vrstanekretnine", title });
|
||||
kiviOriginal.email = "";
|
||||
|
||||
await realEstate.save();
|
||||
|
||||
await kiviOriginal.save();
|
||||
|
||||
res.render("deleteRealEstate", { nextStep: "/", title });
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user