From 31bd472b97bc7853b7a2f6f704b5d0b598764e62 Mon Sep 17 00:00:00 2001 From: Kaitlyn Date: Tue, 3 Dec 2024 11:56:05 -0500 Subject: [PATCH 1/2] Add QA Custom broker data to broker scan results --- src/db/tables/onerep_scans.ts | 65 ++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/src/db/tables/onerep_scans.ts b/src/db/tables/onerep_scans.ts index b6ba56b79e2..daa1a88cac3 100644 --- a/src/db/tables/onerep_scans.ts +++ b/src/db/tables/onerep_scans.ts @@ -411,29 +411,52 @@ async function getScanResultsWithBrokerUnderMaintenance( if (onerepProfileId === null) { return null; } + const qaToggles = await getQaToggleRow(onerepProfileId); + let showCustomBrokers = false; + let showRealBrokers = true; - let scanResults = await knex("onerep_scan_results as sr") - .select( - "sr.*", - "s.*", - "sr.status as scan_result_status", // rename to avoid collision - "db.status as broker_status", // rename to avoid collision - ) - .innerJoin("onerep_scans as s", "sr.onerep_scan_id", "s.onerep_scan_id") - .where("s.onerep_profile_id", onerepProfileId) - .andWhere("sr.manually_resolved", "false") - .andWhereNot("sr.status", "removed") - .join("onerep_data_brokers as db", "sr.data_broker", "db.data_broker") - .orderBy("sr.onerep_scan_result_id"); - - scanResults = scanResults.filter( - (result) => - result.broker_status === "removal_under_maintenance" || - new Date().getTime() - new Date(result.updated_at).getTime() > - CONST_DAY_MILLISECONDS * 200, - ); + if (qaToggles) { + showCustomBrokers = qaToggles.show_custom_brokers; + showRealBrokers = qaToggles.show_real_brokers; + } + const scan = await getLatestOnerepScan(onerepProfileId); + + let results: OnerepScanResultRow[] = []; + + if (showRealBrokers) { + let scanResults = await knex("onerep_scan_results as sr") + .select( + "sr.*", + "s.*", + "sr.status as scan_result_status", // rename to avoid collision + "db.status as broker_status", // rename to avoid collision + ) + .innerJoin("onerep_scans as s", "sr.onerep_scan_id", "s.onerep_scan_id") + .where("s.onerep_profile_id", onerepProfileId) + .andWhere("sr.manually_resolved", "false") + .andWhereNot("sr.status", "removed") + .join("onerep_data_brokers as db", "sr.data_broker", "db.data_broker") + .orderBy("sr.onerep_scan_result_id"); + + scanResults = scanResults.filter( + (result) => + result.broker_status === "removal_under_maintenance" || + new Date().getTime() - new Date(result.updated_at).getTime() > + CONST_DAY_MILLISECONDS * 200, + ); + + results = scanResults; + } + // Fetch custom brokers if allowed + if (showCustomBrokers) { + const qaBrokers = await getQaCustomBrokers( + onerepProfileId, + scan?.onerep_scan_id, + ); + results = [...results, ...qaBrokers]; + } - return { results: scanResults } as LatestOnerepScanData; + return { results } as LatestOnerepScanData; } export { From fc173f78eb8519bbe2ecb508f89fdcd7f92207b0 Mon Sep 17 00:00:00 2001 From: Kaitlyn Date: Tue, 3 Dec 2024 13:17:16 -0500 Subject: [PATCH 2/2] filter manually rsolved --- src/db/tables/onerep_scans.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/db/tables/onerep_scans.ts b/src/db/tables/onerep_scans.ts index daa1a88cac3..89b0b340b01 100644 --- a/src/db/tables/onerep_scans.ts +++ b/src/db/tables/onerep_scans.ts @@ -453,7 +453,11 @@ async function getScanResultsWithBrokerUnderMaintenance( onerepProfileId, scan?.onerep_scan_id, ); - results = [...results, ...qaBrokers]; + const filteredCustomBrokers = qaBrokers.filter( + (broker) => broker.manually_resolved === false, + ); + + results = [...results, ...filteredCustomBrokers]; } return { results } as LatestOnerepScanData;