From ab50eb05af582beae714bc663bc3b24ccd7917c1 Mon Sep 17 00:00:00 2001 From: Naida Vatric Date: Wed, 18 Mar 2020 21:29:11 +0100 Subject: [PATCH] Started deleting of ads. --- app/controllers/deleteRealEstate.js | 23 ++++++++++++++++++++++ app/helpers/emailContentGenerator.js | 29 ++++++++++++++++++++++++---- app/routes/index.js | 3 +++ app/services/notificationService.js | 10 +++++++--- 4 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 app/controllers/deleteRealEstate.js diff --git a/app/controllers/deleteRealEstate.js b/app/controllers/deleteRealEstate.js new file mode 100644 index 0000000..dc840ec --- /dev/null +++ b/app/controllers/deleteRealEstate.js @@ -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 +}; diff --git a/app/helpers/emailContentGenerator.js b/app/helpers/emailContentGenerator.js index 62e66ba..e522876 100644 --- a/app/helpers/emailContentGenerator.js +++ b/app/helpers/emailContentGenerator.js @@ -202,16 +202,37 @@ const generateCheckUpEmail = searchRequest => { ${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 `

${stagingTag}Zdravo

Uspješno ste objavili oglas za Vašu nekretninu na Kivi.ba.

-
U Kivi bazi trenutno postoji ${numberOfMatchingRequests} zahtjeva za nekretninom kao sto je Vaša.
+
U Kivi bazi trenutno ${countingPrefix} ${numberOfMatchingRequests} ${countingSufix} za nekretninom kao sto je Vaša.

Pregledajte Vaš oglas na sljedećem linku: ${realEstate.title}

-
Ako želite izmijeniti detalje oglasa, izmjenite ovdje
-
Ako želite izbrisati Vaš oglas iz Kivi baze, izbrišite ovdje
+
Ako želite izmijeniti detalje oglasa, izmjenite ovdje.
+
Ako želite izbrisati Vaš oglas iz Kivi baze, izbrišite ovdje.

Hvala na ukazanom povjerenju!

diff --git a/app/routes/index.js b/app/routes/index.js index b294210..b23655a 100644 --- a/app/routes/index.js +++ b/app/routes/index.js @@ -24,6 +24,7 @@ const { getGoAgain } = require("../controllers/goAgain"); const { publishSuccess } = require("../controllers/publishSuccess"); const { getLocation, postLocation } = require("../controllers/location"); const { getUnsubscribe } = require("../controllers/unsubscribe"); +const { getDeletePublishedAd } = require("../controllers/deleteRealEstate"); const { getRealEstates } = require("../controllers/realEstates"); const { getRedirect } = require("../controllers/redirect"); const { getFilters, postFilters } = require("../controllers/realEstateFilters"); @@ -59,6 +60,8 @@ router.post("/pregled/:searchRequestId", postQueryReview); router.get("/odjava/:searchRequestId", getUnsubscribe); +router.get("/obrisioglas/:kiviRealEstateId", getDeletePublishedAd); + router.get("/ponovo", getGoAgain); router.get("/uspjesnaobjava", publishSuccess); diff --git a/app/services/notificationService.js b/app/services/notificationService.js index bdcdd84..4f9ff6d 100644 --- a/app/services/notificationService.js +++ b/app/services/notificationService.js @@ -152,13 +152,17 @@ const notifyForNewAdPublish = async (realEstate, kiviOriginal) => { // console.log("Real estate:", realEstate); // console.log("Kivi original:", kiviOriginal); 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 numberOfMatchingRequests = Object.keys(matches).length; + //Counting number of matching req + let numberOfMatchingRequests = 0; + for (const match in matches) { + numberOfMatchingRequests++; + } const emailContent = generateNewAdPublishEmail( realEstate, + kiviOriginal, numberOfMatchingRequests );