find matching real estates for new search request and notify
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
"use strict";
|
||||
const { matchRealEstates } = require("../services/searchMatchService");
|
||||
const {
|
||||
matchRealEstates,
|
||||
matchSearchRequest
|
||||
} = require("../services/searchMatchService");
|
||||
const {
|
||||
generateNotificationEmail,
|
||||
generateNewSearchRequestEmail
|
||||
@@ -8,6 +11,24 @@ const { sendEmail } = require("../services/emailService");
|
||||
|
||||
const notifyForNewRealEstates = async newRealEstates => {
|
||||
const matches = await matchRealEstates(newRealEstates);
|
||||
await notifyMatches(matches);
|
||||
};
|
||||
|
||||
const notifyForNewSearchRequest = async searchRequest => {
|
||||
const matches = await matchSearchRequest(searchRequest);
|
||||
|
||||
const searchRequestId = searchRequest.id;
|
||||
const matchingRealEstates = matches[searchRequestId].realEstates;
|
||||
|
||||
const emailContent = generateNewSearchRequestEmail(
|
||||
searchRequest,
|
||||
matchingRealEstates
|
||||
);
|
||||
const { email } = searchRequest;
|
||||
await sendEmail(email, "Market Alert", emailContent);
|
||||
};
|
||||
|
||||
const notifyMatches = async matches => {
|
||||
const searchRequestsToNotify = Object.keys(matches);
|
||||
|
||||
const asyncSendEmailActions = [];
|
||||
@@ -27,12 +48,6 @@ const notifyForNewRealEstates = async newRealEstates => {
|
||||
await Promise.all(asyncSendEmailActions);
|
||||
};
|
||||
|
||||
const notifyForNewSearchRequest = async searchRequest => {
|
||||
const emailContent = generateNewSearchRequestEmail(searchRequest);
|
||||
const { email } = searchRequest;
|
||||
await sendEmail(email, "Market Alert", emailContent);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
notifyForNewRealEstates,
|
||||
notifyForNewSearchRequest
|
||||
|
||||
Reference in New Issue
Block a user