Skip to content

Commit

Permalink
chore: condense logic to pass sonar guardrails
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevespi committed Oct 17, 2024
1 parent 7eebeea commit ab7b529
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions backend/src/v1/complaint/complaint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1016,21 +1016,6 @@ export class ComplaintService {
complaintBuilder.andWhere("ST_X(complaint.location_geometry_point) <> 0");
complaintBuilder.andWhere("ST_Y(complaint.location_geometry_point) <> 0");

// -- filter by complaint identifiers returned by case management if actionTaken filter is present
// -- Declaring complaintIdentifiersByActionTaken outside of the 'if' so that we have it in scope
// for the unmappedBuilder below without making the same call to CM again.
const complaintIdentifiersByActionTaken: string[] = [];
if (hasCEEBRole && filters.actionTaken) {
const complaintIdentifiers = await this._getComplaintsByActionTaken(token, filters.actionTaken);
complaintIdentifiersByActionTaken.push(...complaintIdentifiers);
complaintBuilder.andWhere("complaint.complaint_identifier IN(:...complaint_identifiers)", {
complaint_identifiers: complaintIdentifiersByActionTaken,
});
}

//-- run query
const mappedComplaints = await complaintBuilder.getMany();

//-- get unmapable complaints
let unMappedBuilder = this._generateQueryBuilder(complaintType);

Expand All @@ -1057,18 +1042,23 @@ export class ComplaintService {
unMappedBuilder.andWhere("violation_code.agency_code = :agency", { agency: "EPO" });
}

//-- filter locations without coordinates
unMappedBuilder.andWhere("ST_X(complaint.location_geometry_point) = 0");
unMappedBuilder.andWhere("ST_Y(complaint.location_geometry_point) = 0");

// -- filter by complaint identifiers returned by case management if actionTaken filter is present
if (hasCEEBRole && filters.actionTaken) {
const complaintIdentifiers = await this._getComplaintsByActionTaken(token, filters.actionTaken);
complaintBuilder.andWhere("complaint.complaint_identifier IN(:...complaint_identifiers)", {
complaint_identifiers: complaintIdentifiers,
});
unMappedBuilder.andWhere("complaint.complaint_identifier IN(:...complaint_identifiers)", {
complaint_identifiers: complaintIdentifiersByActionTaken,
complaint_identifiers: complaintIdentifiers,
});
}

//-- filter locations without coordinates
unMappedBuilder.andWhere("ST_X(complaint.location_geometry_point) = 0");
unMappedBuilder.andWhere("ST_Y(complaint.location_geometry_point) = 0");

//-- run query
//-- run queries
const mappedComplaints = await complaintBuilder.getMany();
const unmappedComplaints = await unMappedBuilder.getCount();
results = { ...results, unmappedComplaints };

Expand Down

0 comments on commit ab7b529

Please sign in to comment.