Skip to content

Commit

Permalink
feat: Release/river otter (#591)
Browse files Browse the repository at this point in the history
Co-authored-by: Barrett Falk <bfalk@salussystems.com>
Co-authored-by: gregorylavery <100631366+gregorylavery@users.noreply.github.com>
Co-authored-by: Mike <100624415+marqueone-ps@users.noreply.github.com>
Co-authored-by: dmitri-korin-bcps <108112696+dmitri-korin-bcps@users.noreply.github.com>
Co-authored-by: Mike Sears <mike.2.sears@gov.bc.ca>
  • Loading branch information
6 people authored Aug 22, 2024
1 parent 2e522f0 commit 33f7f58
Show file tree
Hide file tree
Showing 130 changed files with 4,198 additions and 827 deletions.
4 changes: 4 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import { DocumentModule } from "./v1/document/document.module";
import { CdogsModule } from "./external_api/cdogs/cdogs.module";
import { GirTypeCodeModule } from "./v1/gir_type_code/gir_type_code.module";
import { GeneralIncidentComplaintModule } from "./v1/gir_complaint/gir_complaint.module";
import { FeatureFlagModule } from "./v1/feature_flag/feature_flag.module";
import { FeatureCodeModule } from "./v1/feature_code/feature_code.module";

console.log("Var check - POSTGRESQL_HOST", process.env.POSTGRESQL_HOST);
console.log("Var check - POSTGRESQL_DATABASE", process.env.POSTGRESQL_DATABASE);
Expand Down Expand Up @@ -114,6 +116,8 @@ if (process.env.POSTGRESQL_PASSWORD != null) {
CdogsModule,
GirTypeCodeModule,
GeneralIncidentComplaintModule,
FeatureFlagModule,
FeatureCodeModule,
],
controllers: [AppController],
providers: [AppService, ComplaintSequenceResetScheduler],
Expand Down
11 changes: 11 additions & 0 deletions backend/src/auth/jwtrole.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Reflector } from "@nestjs/core";
import { AuthGuard } from "@nestjs/passport";
import { Role } from "src/enum/role.enum";
import { ROLES_KEY } from "./decorators/roles.decorator";
import { IS_PUBLIC_KEY } from "./decorators/public.decorator";

@Injectable()
/**
Expand All @@ -18,6 +19,16 @@ export class JwtRoleGuard extends AuthGuard("jwt") implements CanActivate {

// returns false if the user does not have the required role indicated by the API's @Roles decorator
canActivate(context: ExecutionContext): boolean {
//-- check to see if the public access decorator is used
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
context.getHandler(),
context.getClass(),
]);

if (isPublic) {
return true;
}

// get the roles associated with the request
const requiredRoles = this.reflector.getAllAndOverride<Role[]>(ROLES_KEY, [
context.getHandler(),
Expand Down
1 change: 1 addition & 0 deletions backend/src/enum/role.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export enum Role {
COS_OFFICER = "COS Officer",
COS_ADMIN = "COS Admin",
CEEB = "CEEB",
TEMPORARY_TEST_ADMIN = "TEMPORARY_TEST_ADMIN",
}
21 changes: 21 additions & 0 deletions backend/src/middleware/maps/automapper-entity-to-dto-maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ export const complaintToComplaintDtoMap = (mapper: Mapper) => {
return delegates;
}),
),
forMember(
(destination) => destination.webeocId,
mapFrom((source) => source.webeoc_identifier),
),
);
};

Expand Down Expand Up @@ -667,6 +671,10 @@ export const applyWildlifeComplaintMap = (mapper: Mapper) => {
return "";
}),
),
forMember(
(destination) => destination.webeocId,
mapFrom((source) => source.complaint_identifier.webeoc_identifier),
),
);
};

Expand Down Expand Up @@ -868,6 +876,10 @@ export const applyAllegationComplaintMap = (mapper: Mapper) => {
(destination) => destination.violationDetails,
mapFrom((src) => src.suspect_witnesss_dtl_text),
),
forMember(
(destination) => destination.webeocId,
mapFrom((source) => source.complaint_identifier.webeoc_identifier),
),
);
};
export const applyGeneralInfomationComplaintMap = (mapper: Mapper) => {
Expand Down Expand Up @@ -1072,6 +1084,7 @@ const girTypeCodeToGirTypeCodeDto = (mapper: Mapper) => {
);
};


//-- reporting data maps
export const mapWildlifeReport = (mapper: Mapper, tz: string = "America/Vancouver") => {
const reportGeneratedOn: Date = new Date();
Expand Down Expand Up @@ -1349,6 +1362,10 @@ export const mapWildlifeReport = (mapper: Mapper, tz: string = "America/Vancouve
return "";
}),
),
forMember(
(destination) => destination.webeocId,
mapFrom((source) => source.complaint_identifier.webeoc_identifier),
),
);
};

Expand Down Expand Up @@ -1610,6 +1627,10 @@ export const mapAllegationReport = (mapper: Mapper, tz: string = "America/Vancou
(destination) => destination.details,
mapFrom((src) => src.suspect_witnesss_dtl_text),
),
forMember(
(destination) => destination.webeocId,
mapFrom((source) => source.complaint_identifier.webeoc_identifier),
),
);
};

Expand Down
10 changes: 10 additions & 0 deletions backend/src/types/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ export const WEBEOC_REPORT_TYPE = {
ERS: "ERS",
GIR: "GIR",
};

export const ACTION_TAKEN_ACTION_TYPES = {
CREATE_ACTION_TAKEN: "ACTIONCTE",
UPDATE_ACTION_TAKEN: "ACTIONUPD",
};

export const ACTION_TAKEN_TYPES = {
ACTION_TAKEN: "ACTION-TAKEN",
ACTION_TAKEN_UPDATE: "ACTION-TAKEN-UPDATE",
};
24 changes: 24 additions & 0 deletions backend/src/types/models/complaints/action-taken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { UUID } from "crypto";

export interface ActionTaken {
actionTakenId: UUID;
complaintId?: string;
complaintUpdateGuid?: UUID;
webeocId?: string; //-- used to lookup complaint_id
loggedBy: string; //--> logged_by_text
actionTimestamp: Date; //--> action_utc_timestamp
details: string; //--> acton_details_text
isUpdate: boolean; //-- flag_UAT === "Yes"
dataid: number;
}

export interface ActionTakenDto {
actionTakenGuid: string;
complaintIdentifier?: string;
complaintUpdateGuid?: string;
actionDetailsTxt?: string;
loggedByTxt?: string;
actionUtcTimestamp?: Date;
}

//{"details": "Action 1 - gir test - edit 1", "isUpdate": false, "loggedBy": "Scarlett Truong", "webeocId": "275908", "complaintId": "24-000558", "actionTakenId": "16ca3bcc-23a8-4930-b0a6-32ab460a702a", "actionTimestamp": "08/12/2024 16:36:52"}
1 change: 1 addition & 0 deletions backend/src/types/models/complaints/complaint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export interface ComplaintDto {
officeLocation?: string;
};
delegates: Array<DelegateDto>;
webeocId: string;
}
7 changes: 7 additions & 0 deletions backend/src/types/models/complaints/related-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ComplaintUpdate } from "src/v1/complaint_updates/entities/complaint_updates.entity";
import { ActionTaken } from "src/v1/complaint/entities/action_taken.entity";

export interface RelatedDataDto {
updates: Array<ComplaintUpdate>;
actions: Array<ActionTaken>;
}
7 changes: 7 additions & 0 deletions backend/src/types/models/complaints/update-complaint.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,11 @@ export class UpdateComplaintDto {
description: "The timestamp when the complaint was last updated",
})
update_utc_timestamp: Date;

@ApiProperty({
example: "123455",
description:
"Unique identifier from the webeoc source system to identify a complaint. This is required as the natural key is not avaialble in all webeoc apis",
})
webeoc_identifier: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface ComplaintReportData {
region: string;
locationDescription: string;
description: string;
webeocId: string;

//-- caller information
name: string;
Expand Down
1 change: 0 additions & 1 deletion backend/src/v1/agency_code/entities/agency_code.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ApiProperty } from "@nestjs/swagger";
import { UUID } from "crypto";
import { Entity, Column, PrimaryColumn } from "typeorm";

@Entity()
Expand Down
12 changes: 12 additions & 0 deletions backend/src/v1/case_file/case_file.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ import { MockGeneralIncidentComplaintRepository } from "../../../test/mocks/mock
import { Office } from "../office/entities/office.entity";
import { Officer } from "../officer/entities/officer.entity";
import { GirTypeCode } from "../gir_type_code/entities/gir_type_code.entity";
import { ComplaintUpdatesService } from "../complaint_updates/complaint_updates.service";
import { ActionTaken } from "../complaint/entities/action_taken.entity";
import { StagingComplaint } from "../staging_complaint/entities/staging_complaint.entity";

describe("Testing: Case File Service", () => {
let service: CaseFileService;
Expand Down Expand Up @@ -163,6 +166,15 @@ describe("Testing: Case File Service", () => {
provide: getRepositoryToken(ComplaintUpdate),
useValue: {},
},
{
provide: getRepositoryToken(StagingComplaint),
useValue: {},
},
{
provide: getRepositoryToken(ActionTaken),
useValue: {},
},
ComplaintUpdatesService,
CaseFileService,
ComplaintService,
CodeTableService,
Expand Down
44 changes: 43 additions & 1 deletion backend/src/v1/complaint/complaint.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@ import { ComplaintDto } from "../../types/models/complaints/complaint";
import { ComplaintSearchParameters } from "../../types/models/complaints/complaint-search-parameters";
import { ZoneAtAGlanceStats } from "src/types/zone_at_a_glance/zone_at_a_glance_stats";
import { GeneralIncidentComplaintDto } from "src/types/models/complaints/gir-complaint";
import { ApiKeyGuard } from "src/auth/apikey.guard";
import { ActionTaken } from "../../types/models/complaints/action-taken";
import { Public } from "src/auth/decorators/public.decorator";
import { StagingComplaintService } from "../staging_complaint/staging_complaint.service";
import { dtoAlias } from "../../types/models/complaints/dtoAlias-type";

import { RelatedDataDto } from "src/types/models/complaints/related-data";
import { ACTION_TAKEN_ACTION_TYPES } from "src/types/constants";

@UseGuards(JwtRoleGuard)
@ApiTags("complaint")
@Controller({
path: "complaint",
version: "1",
})
export class ComplaintController {
constructor(private readonly service: ComplaintService) {}
constructor(private readonly service: ComplaintService, private readonly stagingService: StagingComplaintService) {}
private readonly logger = new Logger(ComplaintController.name);

@Get(":complaintType")
Expand Down Expand Up @@ -75,6 +82,11 @@ export class ComplaintController {
| AllegationComplaintDto
| GeneralIncidentComplaintDto;
}
@Get("/related-data/:id")
@Roles(Role.COS_OFFICER, Role.CEEB)
async findRelatedDataById(@Param("id") id: string): Promise<RelatedDataDto> {
return await this.service.findRelatedDataById(id);
}

@Post("/create/:complaintType")
@Roles(Role.COS_OFFICER, Role.CEEB)
Expand All @@ -93,4 +105,34 @@ export class ComplaintController {
): Promise<ZoneAtAGlanceStats> {
return this.service.getZoneAtAGlanceStatistics(complaintType, zone);
}

@Public()
@Post("/staging/action-taken")
@UseGuards(ApiKeyGuard)
stageActionTaken(@Body() action: ActionTaken) {
this.stagingService.stageObject("ACTION-TAKEN", action);
}

@Public()
@Post("/staging/action-taken-update")
@UseGuards(ApiKeyGuard)
stageActionTakenUpdate(@Body() action: ActionTaken) {
this.stagingService.stageObject("ACTION-TAKEN-UPDATE", action);
}

@Public()
@Post("/process/action-taken/:id")
@UseGuards(ApiKeyGuard)
processActionTaken(@Param("id") id: string, @Body() payload: any) {
const { dataid } = payload;
this.stagingService.processObject(ACTION_TAKEN_ACTION_TYPES.CREATE_ACTION_TAKEN, id, dataid);
}

@Public()
@Post("/process/action-taken-update/:id")
@UseGuards(ApiKeyGuard)
processActionTakenUpdate(@Param("id") id: string, @Body() payload: any) {
const { dataid } = payload;
this.stagingService.processObject(ACTION_TAKEN_ACTION_TYPES.UPDATE_ACTION_TAKEN, id, dataid);
}
}
4 changes: 4 additions & 0 deletions backend/src/v1/complaint/complaint.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { AutomapperModule } from "@automapper/nestjs";
import { GirComplaint } from "../gir_complaint/entities/gir_complaint.entity";
import { ComplaintUpdate } from "../complaint_updates/entities/complaint_updates.entity";
import { ComplaintUpdatesModule } from "../complaint_updates/complaint_updates.module";
import { StagingComplaintModule } from "../staging_complaint/staging_complaint.module";
import { ActionTaken } from "./entities/action_taken.entity";

@Module({
imports: [
Expand All @@ -49,11 +51,13 @@ import { ComplaintUpdatesModule } from "../complaint_updates/complaint_updates.m
TypeOrmModule.forFeature([GirComplaint]),
TypeOrmModule.forFeature([ComplaintUpdate]),
TypeOrmModule.forFeature([GirComplaint]),
TypeOrmModule.forFeature([ActionTaken]),
CodeTableModule,
PersonComplaintXrefModule,
AttractantHwcrXrefModule,
AutomapperModule,
ComplaintUpdatesModule,
StagingComplaintModule,
],
controllers: [ComplaintController],
providers: [ComplaintService],
Expand Down
21 changes: 21 additions & 0 deletions backend/src/v1/complaint/complaint.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ import { dataSourceMockFactory } from "../../../test/mocks/datasource";
import { ComplaintSearchParameters } from "../../types/models/complaints/complaint-search-parameters";
import { GirTypeCode } from "../gir_type_code/entities/gir_type_code.entity";
import { GirComplaint } from "../gir_complaint/entities/gir_complaint.entity";
import { ComplaintUpdatesService } from "../complaint_updates/complaint_updates.service";
import { ActionTaken } from "./entities/action_taken.entity";
import { StagingComplaint } from "../staging_complaint/entities/staging_complaint.entity";

describe("Testing: Complaint Service", () => {
let service: ComplaintService;
Expand All @@ -77,6 +80,15 @@ describe("Testing: Complaint Service", () => {
strategyInitializer: pojos(),
}),
},
{
provide: getRepositoryToken(StagingComplaint),
useValue: {},
},
{
provide: getRepositoryToken(ActionTaken),
useValue: {},
},
ComplaintUpdatesService,
ComplaintService,
PersonComplaintXrefService,
AttractantHwcrXrefService,
Expand Down Expand Up @@ -319,6 +331,15 @@ describe("Testing: Complaint Service", () => {
strategyInitializer: pojos(),
}),
},
{
provide: getRepositoryToken(StagingComplaint),
useValue: {},
},
{
provide: getRepositoryToken(ActionTaken),
useValue: {},
},
ComplaintUpdatesService,
ComplaintService,
PersonComplaintXrefService,
AttractantHwcrXrefService,
Expand Down
Loading

0 comments on commit 33f7f58

Please sign in to comment.