add condition for sending emails based on email frequency property
This commit is contained in:
@@ -6,6 +6,7 @@ const {
|
||||
const { findRealEstatesForSearchRequest } = require("../helpers/db/realEstate");
|
||||
const { addMatches } = require("../helpers/db/searchRequestMatch");
|
||||
const { MAX_REAL_ESTATES_IN_FIRST_EMAIL } = require("../config/appConfig");
|
||||
const { EMAIL_FREQUENCY } = require("../common/enums");
|
||||
|
||||
const matchRealEstates = async realEstates => {
|
||||
if (Array.isArray(realEstates)) {
|
||||
@@ -18,18 +19,19 @@ const matchRealEstates = async realEstates => {
|
||||
|
||||
searchRequestsPromise.then(searchRequests => {
|
||||
for (const searchRequest of searchRequests) {
|
||||
const { id } = searchRequest;
|
||||
const { id, emailFrequency } = searchRequest;
|
||||
if (!matches[id]) {
|
||||
matches[id] = {
|
||||
searchRequest,
|
||||
realEstates: []
|
||||
realEstates: [],
|
||||
notifyNow: emailFrequency === EMAIL_FREQUENCY.ASAP.stringId
|
||||
};
|
||||
}
|
||||
matches[id].realEstates.push(realEstate);
|
||||
matchingRecords.push({
|
||||
searchRequestId: searchRequest.id,
|
||||
realEstateId: realEstate.id,
|
||||
notified: false
|
||||
notified: emailFrequency === EMAIL_FREQUENCY.ASAP.stringId
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -62,7 +64,7 @@ const matchSearchRequest = async searchRequest => {
|
||||
matchingRecords.push({
|
||||
searchRequestId,
|
||||
realEstateId: realEstate.id,
|
||||
notified: false
|
||||
notified: true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user