From 5b2961d992057d6c863dc2635373468ad907d67c Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Mon, 4 Nov 2019 10:59:51 +0100 Subject: [PATCH] add db helper for searching not notified search request matches --- app/helpers/db/searchRequestMatch.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/helpers/db/searchRequestMatch.js b/app/helpers/db/searchRequestMatch.js index d7cb215..11d5cde 100644 --- a/app/helpers/db/searchRequestMatch.js +++ b/app/helpers/db/searchRequestMatch.js @@ -24,6 +24,23 @@ const findRealEstatesForSearchRequest = async searchRequestId => { return matchingRealEstates; }; +const findNotNotifiedMatches = async () => { + const query = { + notified: false + }; + + const searchRequestsModel = { model: db.SearchRequest, as: "searchRequests" }; + const realEstateModel = { model: db.RealEstate, as: "realEstates" }; + const include = [searchRequestsModel, realEstateModel]; + + const matchingRecords = await db.SearchRequestMatch.findAll({ + where: query, + include + }); + + return matchingRecords; +}; + const addMatches = async matchingRecords => { return await db.SearchRequestMatch.bulkCreate(matchingRecords, { ignoreDuplicates: true @@ -32,5 +49,6 @@ const addMatches = async matchingRecords => { module.exports = { findRealEstatesForSearchRequest, - addMatches + addMatches, + findNotNotifiedMatches };