Skip to content

Commit

Permalink
Merge pull request #5322 from mozilla/MNTOR-3815
Browse files Browse the repository at this point in the history
MNTOR-3815: call for scan results with broker under maintenance
  • Loading branch information
mansaj authored Nov 20, 2024
2 parents b4b65f4 + 826be42 commit 54a859d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { RemovalUnderMaintenanceView } from "./RemovalUnderMaintenanceView";
import { StepDeterminationData } from "../../../../../../../../../functions/server/getRelevantGuidedSteps";
import { getCountryCode } from "../../../../../../../../../functions/server/getCountryCode";
import { headers } from "next/headers";
import { getLatestOnerepScanResults } from "../../../../../../../../../../db/tables/onerep_scans";
import {
getLatestOnerepScanResults,
// getScanResultsWithBrokerUnderMaintenance,
} from "../../../../../../../../../../db/tables/onerep_scans";
import { getOnerepProfileId } from "../../../../../../../../../../db/tables/subscribers";
import { getSubscriberBreaches } from "../../../../../../../../../functions/server/getSubscriberBreaches";
import { getSubscriberEmails } from "../../../../../../../../../functions/server/getSubscriberEmails";
Expand Down
File renamed without changes.
35 changes: 34 additions & 1 deletion src/db/tables/onerep_scans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import {
} from "knex/types/tables";
import { RemovalStatus } from "../../app/functions/universal/scanResult.js";
import { getQaCustomBrokers, getQaToggleRow } from "./qa_customs.ts";
import { DataBrokerRow } from "../../knex-tables";

const knex = createDbConnection();

export interface LatestOnerepScanData {
scan: OnerepScanRow | null;
results: OnerepScanResultRow[];
results: OnerepScanResultRow[] | (OnerepScanResultRow & DataBrokerRow)[];
}

async function getAllScansForProfile(
Expand Down Expand Up @@ -397,6 +398,37 @@ async function getEmailForProfile(onerepProfileId: number) {
}
}

async function getScanResultsWithBrokerUnderMaintenance(
onerepProfileId: number | null,
) {
if (onerepProfileId === null) {
return null;
}

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() >
200 * 24 * 60 * 60 * 1000,
);

return { results: scanResults } as LatestOnerepScanData;
}

export {
getAllScansForProfile,
getLatestScanForProfileByReason,
Expand All @@ -415,4 +447,5 @@ export {
deleteScanResultsForProfile,
deleteSomeScansForProfile,
getEmailForProfile,
getScanResultsWithBrokerUnderMaintenance,
};
2 changes: 1 addition & 1 deletion src/scripts/cronjobs/syncOnerepDataBrokers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import Sentry from "@sentry/nextjs";
import { getAllDataBrokers } from "../../app/functions/server/onerep";
import { upsertDataBrokers } from "../../db/tables/data_brokers.js";
import { upsertDataBrokers } from "../../db/tables/onerep_data_brokers.js";
import {
redisClient,
REDIS_ALL_DATA_BROKERS_KEY,
Expand Down

0 comments on commit 54a859d

Please sign in to comment.