Skip to content

Commit

Permalink
Merge branch 'release/yellow-boring-sponge' into fix/CE-1198-cannot-a…
Browse files Browse the repository at this point in the history
…dd-animal-after-emptied-drugs
  • Loading branch information
afwilcox authored Nov 26, 2024
2 parents e2f0d72 + d77bae4 commit f9777d0
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 3 deletions.
3 changes: 3 additions & 0 deletions backend/src/enum/case_management_error.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export enum CaseManagementError {
DECISION_ACTION_EXIST = "Decision Action Exist",
}
22 changes: 20 additions & 2 deletions backend/src/v1/case_file/case_file.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
import { Controller, Get, Body, Patch, Param, UseGuards, Post, Delete, Query, Logger } from "@nestjs/common";
import {
Controller,
Get,
Body,
Patch,
Param,
UseGuards,
Post,
Delete,
Query,
Logger,
HttpException,
HttpStatus,
} from "@nestjs/common";
import { CaseFileService } from "./case_file.service";
import { Role } from "../../enum/role.enum";
import { Roles } from "../../auth/decorators/roles.decorator";
Expand All @@ -18,6 +31,7 @@ import { UpdateDecisionInput } from "../../types/models/case-files/ceeb/decision
import { CreateAuthorizationOutcomeInput } from "../../types/models/case-files/ceeb/site/create-authorization-outcome-input";
import { UpdateAuthorizationOutcomeInput } from "../../types/models/case-files/ceeb/site/update-authorization-outcome-input";
import { DeleteAuthorizationOutcomeInput } from "../../types/models/case-files/ceeb/site/delete-authorization-outcome-input";
import { CaseManagementError } from "src/enum/case_management_error.enum";

@UseGuards(JwtRoleGuard)
@ApiTags("case")
Expand Down Expand Up @@ -163,7 +177,11 @@ export class CaseFileController {
@Roles(Role.CEEB)
async createDecision(@Token() token, @Body() model: CreateDecisionInput): Promise<CaseFileDto> {
const result = await this.service.createDecision(token, model);
return result;
if (result === CaseManagementError.DECISION_ACTION_EXIST) {
throw new HttpException("Decision Action Exist", HttpStatus.CONFLICT);
} else {
return result;
}
}

@Patch("/decision")
Expand Down
10 changes: 9 additions & 1 deletion backend/src/v1/case_file/case_file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { getIdirFromRequest } from "../../common/get-idir-from-request";
import { CodeTableService } from "../code-table/code-table.service";
import { Complaint } from "../complaint/entities/complaint.entity";
import { CreateLinkedComplaintXrefDto } from "../linked_complaint_xref/dto/create-linked_complaint_xref.dto";
import { CaseManagementError } from "../../enum/case_management_error.enum";

@Injectable({ scope: Scope.REQUEST })
export class CaseFileService {
Expand Down Expand Up @@ -492,7 +493,14 @@ export class CaseFileService {
return returnValue?.deleteWildlife;
};

createDecision = async (token: any, model: CreateDecisionInput): Promise<CaseFileDto> => {
createDecision = async (token: any, model: CreateDecisionInput): Promise<CaseFileDto | CaseManagementError> => {
const { leadIdentifier: leadId } = model;
const caseFile = await this.find(leadId, token);

if (caseFile?.decision?.actionTaken) {
return CaseManagementError.DECISION_ACTION_EXIST;
}

const result = await post(token, {
query: `mutation createDecision($input: CreateDecisionInput!) {
createDecision(input: $input) {
Expand Down
55 changes: 55 additions & 0 deletions exports/cos_hwcr_complaint_export.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
-----------------------------------------------------
-- Monthly HWCR Complaint Export query to be run for COS statistics
-- see https://github.com/bcgov/nr-compliance-enforcement/wiki/Data-Exports for more information
-----------------------------------------------------
select
cmp.complaint_identifier as "Complaint Identifier",
case
when hwc.complaint_identifier is not null then 'HWCR'
else 'Unknown'
end as "Complaint Type",
((cmp.incident_reported_utc_timestmp at time zone 'UTC') at time zone 'PDT') as "Date Logged (PDT)",
((cmp.incident_utc_datetime at time zone 'UTC') at time zone 'PDT') as "Incident Datetime (PDT)",
cst.short_description as "Complaint Status",
spc.short_description as "Species",
case
when hch.data_after_executed_operation ->> 'species_code' != hwc.species_code THEN 'YES!'
else ''
END AS "Was species changed?",
hnc.long_description as "Nature of Complaint",
coalesce (cup.update_count, 0) as "Number of Updates",
goc.short_description as "Area/Community",
gfv.offloc_name as "District",
gfv.zone_name as "Zone",
gfv.region_name as "Region",
ST_X(cmp.location_geometry_point) AS "Longitude (X)",
ST_Y(cmp.location_geometry_point) AS "Latitude (Y)",
per.last_name || ', ' || per.first_name as "Officer Assigned"
from
complaint cmp
join
complaint_status_code cst on cst.complaint_status_code = cmp.complaint_status_code
join
geo_organization_unit_code goc on goc.geo_organization_unit_code = cmp.geo_organization_unit_code
join
cos_geo_org_unit_flat_vw gfv on gfv.area_code = goc.geo_organization_unit_code
left join
person_complaint_xref pcx on pcx.complaint_identifier = cmp.complaint_identifier and pcx.active_ind = true
left join
person per on per.person_guid = pcx.person_guid
right join
hwcr_complaint hwc on hwc.complaint_identifier = cmp.complaint_identifier
left join
species_code spc on spc.species_code = hwc.species_code
left join
hwcr_complaint_nature_code hnc on hnc.hwcr_complaint_nature_code = hwc.hwcr_complaint_nature_code
left join (
select complaint_identifier, count(*) as update_count
from complaint_update
group by complaint_identifier
) cup on cup.complaint_identifier = cmp.complaint_identifier
LEFT JOIN
hwcr_complaint_h hch ON hch.target_row_id = hwc.hwcr_complaint_guid
AND hch.operation_type = 'I'
order by
cmp.complaint_identifier asc
9 changes: 9 additions & 0 deletions frontend/src/app/common/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ApiRequestParameters } from "@apptypes/app/api-request-parameters";
import { toggleLoading, toggleNotification } from "@store/reducers/app";
import { store } from "@store/store";
import { ToggleError } from "./toast";
import { displayBackendErrors } from "./methods";

interface NatComRequestConfig extends AxiosRequestConfig {
toggleLoading: boolean;
Expand All @@ -21,6 +22,7 @@ const STATUS_CODES = {
InternalServerError: 500,
BadGateway: 502,
ServiceUnavailable: 503,
Conflict: 409,
};

let requestCounter = 0;
Expand Down Expand Up @@ -63,6 +65,13 @@ axios.interceptors.response.use(
if (response && response.status === STATUS_CODES.Forbiden) {
ToggleError("User is not authorized to perform this action");
}

if (response && response.status === STATUS_CODES.Conflict) {
const backendErrorText = (response.data as any)?.message;
if (backendErrorText) {
displayBackendErrors(backendErrorText);
}
}
},
);

Expand Down
13 changes: 13 additions & 0 deletions frontend/src/app/common/methods.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { GirType } from "@apptypes/app/code-tables/gir-type";
import { WildlifeComplaint as WildlifeComplaintDto } from "@apptypes/app/complaints/wildlife-complaint";
import { AllegationComplaint as AllegationComplaintDto } from "@apptypes/app/complaints/allegation-complaint";
import { GeneralIncidentComplaint as GeneralIncidentComplaintDto } from "@apptypes/app/complaints/general-complaint";
import { ToggleError } from "./toast";
let utmObj = require("utm-latlng");

type Coordinate = number[] | string[] | undefined;
Expand Down Expand Up @@ -465,6 +466,18 @@ export const latLngToUtm = (lat: string, lng: string): { easting: string; northi
return { easting: "", northing: "", zone: "" };
};


export function getDropdownOption(matchValue: string | undefined | null, optionsList: Option[]): Option | undefined {
return optionsList.find((item) => item.value === matchValue);
}

export const displayBackendErrors = (message: string) => {
switch (message) {
case "Decision Action Exist":
ToggleError(
"Error. This section has been updated while open for editing. Refresh the page to see the most recent changes.",
);
break;
default:
}
};
3 changes: 3 additions & 0 deletions frontend/src/app/store/reducers/case-thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,9 @@ export const upsertDecisionOutcome =

if (!current?.id) {
result = await dispatch(_createDecision(id, decision));
if (!result) {
return "error";
}
} else {
const update = { ...decision, id: current.id };
result = await dispatch(_updateDecison(id, update));
Expand Down

0 comments on commit f9777d0

Please sign in to comment.