Added notification for new ad pusblish and new real estate.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
const { findRealEstateByAgencyId } = require("../helpers/db/realEstate");
|
||||
const { bulkUpsertKiviPhotos } = require("../helpers/db/kiviOriginalAdsPhotos");
|
||||
const { currentKiviRealEstate } = require("../helpers/url");
|
||||
|
||||
const {
|
||||
notifyForNewRealEstates,
|
||||
notifyForNewAdPublish
|
||||
} = require("../services/notificationService");
|
||||
const validate = require("validate.js");
|
||||
|
||||
const {
|
||||
@@ -318,6 +321,11 @@ const postPublishInputs = async (req, res) => {
|
||||
|
||||
await kiviOriginal.save();
|
||||
|
||||
//Calling function to notify real estate owner that ads is published on Kivi page after 1 sec
|
||||
setTimeout(notifyForNewAdPublish, 1000, realEstate, kiviOriginal);
|
||||
//Calling function to notify users of new real estate after 2 min
|
||||
setTimeout(notifyForNewRealEstates, 1000 * 60 * 2, [realEstate]);
|
||||
|
||||
res.redirect(nextStepPage);
|
||||
};
|
||||
|
||||
|
||||
@@ -202,9 +202,26 @@ const generateCheckUpEmail = searchRequest => {
|
||||
${emailFooter}`;
|
||||
};
|
||||
|
||||
const generateNewAdPublishEmail = (realEstate, numberOfMatchingRequests) => {
|
||||
return `<h3>${stagingTag}Zdravo</h3>
|
||||
<div>Uspješno ste objavili oglas za Vašu nekretninu na <strong>Kivi.ba.</strong><div>
|
||||
<br/>
|
||||
<div>U Kivi bazi trenutno postoji ${numberOfMatchingRequests} zahtjeva za nekretninom kao sto je Vaša.</div>
|
||||
<br />
|
||||
<div>Pregledajte Vaš oglas na sljedećem linku: <a href="${realEstate.url}" rel="noreferrer">${realEstate.title}</a><div>
|
||||
<br/>
|
||||
<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>
|
||||
<br/>
|
||||
<div>Hvala na ukazanom povjerenju!</div>
|
||||
<br/>
|
||||
<strong>Vaš,<br/>Kivi tim</strong>`;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
generateNotificationEmail,
|
||||
generateNewSearchRequestEmail,
|
||||
generateEmailSubject,
|
||||
generateCheckUpEmail
|
||||
generateCheckUpEmail,
|
||||
generateNewAdPublishEmail
|
||||
};
|
||||
|
||||
@@ -11,7 +11,8 @@ const {
|
||||
generateNotificationEmail,
|
||||
generateNewSearchRequestEmail,
|
||||
generateEmailSubject,
|
||||
generateCheckUpEmail
|
||||
generateCheckUpEmail,
|
||||
generateNewAdPublishEmail
|
||||
} = require("../helpers/emailContentGenerator");
|
||||
const {
|
||||
findNotNotifiedMatches,
|
||||
@@ -147,9 +148,27 @@ const checkUpNotify = async () => {
|
||||
await Promise.all(asyncSendEmailActions);
|
||||
};
|
||||
|
||||
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 matches = await matchRealEstates([realEstate]);
|
||||
|
||||
const numberOfMatchingRequests = Object.keys(matches).length;
|
||||
|
||||
const emailContent = generateNewAdPublishEmail(
|
||||
realEstate,
|
||||
numberOfMatchingRequests
|
||||
);
|
||||
|
||||
await sendEmail(email, emailSubject, emailContent);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
notifyForNewRealEstates,
|
||||
notifyForNewSearchRequest,
|
||||
notifyRequestsWithDailyOption,
|
||||
notifyForNewAdPublish,
|
||||
checkUpNotify
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user