Changed logic for checkup.For testing.

This commit is contained in:
Naida Vatric
2020-01-24 01:01:10 +01:00
parent b2c102bc1a
commit 40509d2836
6 changed files with 37 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
"use strict";
const db = require("../../models/index");
const { CHECK_UP_DAYS } = require("../../config/appConfig");
const findRealEstatesForSearchRequest = async searchRequestId => {
const query = {
@@ -41,8 +42,27 @@ const findNotNotifiedMatches = async () => {
return matchingRecords;
};
const findAllRequestsForCheckUp = async () => {
//First we find IDs of search request that don't need to be emailed for check up - to EXCLUDE
//The ones that received notification for real estate CHECK_UP_DAYS days from now
const date = new Date();
const checkUpDate = date.getDate() - CHECK_UP_DAYS;
date.setDate(checkUpDate);
const dateQuery = {
createdAt: {
[Op.gte]: date
}
};
const excludedRequests = await db.SearchRequestMatch.findAll({
attributes: ["searchRequestId"],
where: dateQuery
});
const query = {
subscribed: true
subscribed: true,
id: {
[Op.notIn]: excludedRequests
}
};
const allRequestsForCheckUp = await db.SearchRequest.findAll({
where: query