Skip to content

Commit

Permalink
Fix mapSearch agency check for CEEB users
Browse files Browse the repository at this point in the history
Complaints service's mapSearch function uses the local function _getAgencyByUser
to determine a users agency. This function identifies a users agency through
the office they are assigned to. CEEB users have no office assigned, thus
_getAgencyByUser fails. To get around this, mapSearch now uses the hasCEEBRole
variable already included to determine if _getAgencyByUser should be called, or
"EPO" should be assigned (as is the case for CEEB users). Current implementation
of tests do not address the problem, and there was an existing false positive in
the tests for the complaints service. This will be addressed separately.
  • Loading branch information
mikevespi committed Nov 4, 2024
1 parent 8f34d9f commit 6878587
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions backend/src/v1/complaint/complaint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,15 @@ export class ComplaintService {
.where("officer.user_id = :idir", { idir });

const result = await builder.getOne();

//-- pull the user's agency from the query results and return the agency code
const {
office_guid: { agency_code },
} = result;
return agency_code;
if (result.office_guid && result.office_guid.agency_code) {
const {
office_guid: { agency_code },
} = result;
return agency_code;
} else {
return null;
}
};

private _getSortTable = (column: string): string => {
Expand Down Expand Up @@ -986,9 +989,10 @@ export class ComplaintService {
try {
let results: MapSearchResults = { complaints: [], unmappedComplaints: 0 };

//-- get the users assigned agency
const agency = await this._getAgencyByUser();

//-- assign the users agency
// _getAgencyByUser traces agency through assigned office of the officer, which CEEB users do not have
// so the hasCEEBRole is used to assign agency for them.
const agency = hasCEEBRole ? "EPO" : (await this._getAgencyByUser()).agency_code;
//-- search for complaints
let complaintBuilder = this._generateQueryBuilder(complaintType);

Expand All @@ -1005,7 +1009,7 @@ export class ComplaintService {
//-- only return complaints for the agency the user is associated with
if (agency) {
complaintBuilder.andWhere("complaint.owned_by_agency_code.agency_code = :agency", {
agency: agency.agency_code,
agency: agency,
});
}

Expand Down Expand Up @@ -1035,7 +1039,7 @@ export class ComplaintService {
//-- only return complaints for the agency the user is associated with
if (agency) {
unMappedBuilder.andWhere("complaint.owned_by_agency_code.agency_code = :agency", {
agency: agency.agency_code,
agency: agency,
});
}

Expand Down

0 comments on commit 6878587

Please sign in to comment.