Started deleting of ads.
This commit is contained in:
23
app/controllers/deleteRealEstate.js
Normal file
23
app/controllers/deleteRealEstate.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
const { currentSearchRequest } = require("../helpers/url");
|
||||||
|
|
||||||
|
const getDeletePublishedAd = async (req, res) => {
|
||||||
|
const title = "Uspješno ste izbrisali svoj oglas iz baze.";
|
||||||
|
|
||||||
|
const searchRequest = await currentSearchRequest(req);
|
||||||
|
|
||||||
|
if (!searchRequest || !searchRequest.dataValues) {
|
||||||
|
res.render("notFound", { title: " " });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
searchRequest.subscribed = false;
|
||||||
|
searchRequest.deletedEmail = searchRequest.email;
|
||||||
|
searchRequest.email = "";
|
||||||
|
await searchRequest.save();
|
||||||
|
|
||||||
|
res.render("unsubscribe", { nextStep: "/vrstanekretnine", title });
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getDeletePublishedAd
|
||||||
|
};
|
||||||
@@ -202,16 +202,37 @@ const generateCheckUpEmail = searchRequest => {
|
|||||||
${emailFooter}`;
|
${emailFooter}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateNewAdPublishEmail = (realEstate, numberOfMatchingRequests) => {
|
const generateNewAdPublishEmail = (
|
||||||
|
realEstate,
|
||||||
|
kiviOriginal,
|
||||||
|
numberOfMatchingRequests
|
||||||
|
) => {
|
||||||
|
let countingPrefix;
|
||||||
|
if (
|
||||||
|
numberOfMatchingRequests === 2 ||
|
||||||
|
numberOfMatchingRequests === 3 ||
|
||||||
|
numberOfMatchingRequests === 4
|
||||||
|
) {
|
||||||
|
countingPrefix = "postoje";
|
||||||
|
} else {
|
||||||
|
countingPrefix = "postoji";
|
||||||
|
}
|
||||||
|
let countingSufix;
|
||||||
|
if (numberOfMatchingRequests % 10 === 1 && numberOfMatchingRequests !== 11) {
|
||||||
|
countingSufix = "zahtjev";
|
||||||
|
} else {
|
||||||
|
countingSufix = "zahtjeva";
|
||||||
|
}
|
||||||
|
|
||||||
return `<h3>${stagingTag}Zdravo</h3>
|
return `<h3>${stagingTag}Zdravo</h3>
|
||||||
<div>Uspješno ste objavili oglas za Vašu nekretninu na <strong>Kivi.ba.</strong><div>
|
<div>Uspješno ste objavili oglas za Vašu nekretninu na <strong>Kivi.ba.</strong><div>
|
||||||
<br/>
|
<br/>
|
||||||
<div>U Kivi bazi trenutno postoji ${numberOfMatchingRequests} zahtjeva za nekretninom kao sto je Vaša.</div>
|
<div>U Kivi bazi trenutno ${countingPrefix} ${numberOfMatchingRequests} ${countingSufix} za nekretninom kao sto je Vaša.</div>
|
||||||
<br />
|
<br />
|
||||||
<div>Pregledajte Vaš oglas na sljedećem linku: <a href="${realEstate.url}" rel="noreferrer">${realEstate.title}</a><div>
|
<div>Pregledajte Vaš oglas na sljedećem linku: <a href="${realEstate.url}" rel="noreferrer">${realEstate.title}</a><div>
|
||||||
<br/>
|
<br/>
|
||||||
<div>Ako želite izmijeniti detalje oglasa, <a href="#">izmjenite ovdje</a></div>
|
<div>Ako želite izmijeniti detalje oglasa, <a href="#">izmjenite ovdje.</a></div>
|
||||||
<div>Ako želite izbrisati Vaš oglas iz Kivi baze, <a href="#">izbrišite ovdje</a></div>
|
<div>Ako želite izbrisati Vaš oglas iz Kivi baze, <a href="${APP_URL}/obrisioglas/${kiviOriginal.kiviAdId}">izbrišite ovdje.</a></div>
|
||||||
<br/>
|
<br/>
|
||||||
<div>Hvala na ukazanom povjerenju!</div>
|
<div>Hvala na ukazanom povjerenju!</div>
|
||||||
<br/>
|
<br/>
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const { getGoAgain } = require("../controllers/goAgain");
|
|||||||
const { publishSuccess } = require("../controllers/publishSuccess");
|
const { publishSuccess } = require("../controllers/publishSuccess");
|
||||||
const { getLocation, postLocation } = require("../controllers/location");
|
const { getLocation, postLocation } = require("../controllers/location");
|
||||||
const { getUnsubscribe } = require("../controllers/unsubscribe");
|
const { getUnsubscribe } = require("../controllers/unsubscribe");
|
||||||
|
const { getDeletePublishedAd } = require("../controllers/deleteRealEstate");
|
||||||
const { getRealEstates } = require("../controllers/realEstates");
|
const { getRealEstates } = require("../controllers/realEstates");
|
||||||
const { getRedirect } = require("../controllers/redirect");
|
const { getRedirect } = require("../controllers/redirect");
|
||||||
const { getFilters, postFilters } = require("../controllers/realEstateFilters");
|
const { getFilters, postFilters } = require("../controllers/realEstateFilters");
|
||||||
@@ -59,6 +60,8 @@ router.post("/pregled/:searchRequestId", postQueryReview);
|
|||||||
|
|
||||||
router.get("/odjava/:searchRequestId", getUnsubscribe);
|
router.get("/odjava/:searchRequestId", getUnsubscribe);
|
||||||
|
|
||||||
|
router.get("/obrisioglas/:kiviRealEstateId", getDeletePublishedAd);
|
||||||
|
|
||||||
router.get("/ponovo", getGoAgain);
|
router.get("/ponovo", getGoAgain);
|
||||||
|
|
||||||
router.get("/uspjesnaobjava", publishSuccess);
|
router.get("/uspjesnaobjava", publishSuccess);
|
||||||
|
|||||||
@@ -152,13 +152,17 @@ const notifyForNewAdPublish = async (realEstate, kiviOriginal) => {
|
|||||||
// console.log("Real estate:", realEstate);
|
// console.log("Real estate:", realEstate);
|
||||||
// console.log("Kivi original:", kiviOriginal);
|
// console.log("Kivi original:", kiviOriginal);
|
||||||
const email = kiviOriginal.dataValues.email;
|
const email = kiviOriginal.dataValues.email;
|
||||||
const emailSubject = `${stagingTag}Kivi: Uspješno ste objavili oglas!`;
|
const emailSubject = `${stagingTag}Kivi - Uspješno ste objavili oglas!`;
|
||||||
const matches = await matchRealEstates([realEstate]);
|
const matches = await matchRealEstates([realEstate]);
|
||||||
|
//Counting number of matching req
|
||||||
const numberOfMatchingRequests = Object.keys(matches).length;
|
let numberOfMatchingRequests = 0;
|
||||||
|
for (const match in matches) {
|
||||||
|
numberOfMatchingRequests++;
|
||||||
|
}
|
||||||
|
|
||||||
const emailContent = generateNewAdPublishEmail(
|
const emailContent = generateNewAdPublishEmail(
|
||||||
realEstate,
|
realEstate,
|
||||||
|
kiviOriginal,
|
||||||
numberOfMatchingRequests
|
numberOfMatchingRequests
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user