diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 7b4d2f76..2b1aed1f 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -246,6 +246,7 @@ model agency_code { agency_code String @id(map: "PK_agency_code") @db.VarChar(10) short_description String? @db.VarChar(50) long_description String? @db.VarChar(250) + display_order Int? active_ind Boolean? create_user_id String @db.VarChar(32) create_utc_timestamp DateTime @db.Timestamp(6) @@ -467,7 +468,7 @@ model decision { discharge_code String @db.VarChar(10) rationale_code String? @db.VarChar(10) inspection_number Int? - lead_agency String? @db.VarChar(10) + lead_agency_code String? @db.VarChar(10) non_compliance_decision_matrix_code String? @db.VarChar(10) active_ind Boolean create_user_id String @db.VarChar(32) diff --git a/backend/src/agency_code/agency_code.graphql b/backend/src/agency_code/agency_code.graphql new file mode 100644 index 00000000..c9b0ccc3 --- /dev/null +++ b/backend/src/agency_code/agency_code.graphql @@ -0,0 +1,11 @@ +type AgencyCode { + agencyCode: String + shortDescription: String + longDescription: String + displayOrder: Int + activeIndicator: Boolean +} + +type Query { + agencyCodes: [AgencyCode]! +} diff --git a/backend/src/agency_code/agency_code.module.ts b/backend/src/agency_code/agency_code.module.ts new file mode 100644 index 00000000..c68e503c --- /dev/null +++ b/backend/src/agency_code/agency_code.module.ts @@ -0,0 +1,10 @@ +import { Module } from "@nestjs/common"; +import { AgencyCodeService } from "./agency_code.service"; +import { AgencyCodeResolver } from "./agency_code.resolver"; +import { PrismaModule } from "nestjs-prisma"; + +@Module({ + imports: [PrismaModule], + providers: [AgencyCodeResolver, AgencyCodeService], +}) +export class AgencyCodeModule {} diff --git a/backend/src/agency_code/agency_code.resolver.spec.ts b/backend/src/agency_code/agency_code.resolver.spec.ts new file mode 100644 index 00000000..90fc95a9 --- /dev/null +++ b/backend/src/agency_code/agency_code.resolver.spec.ts @@ -0,0 +1,21 @@ +import { Test, TestingModule } from "@nestjs/testing"; +import { AgencyCodeResolver } from "./agency_code.resolver"; +import { AgencyCodeService } from "./agency_code.service"; +import { PrismaModule } from "nestjs-prisma"; + +describe("AgencyCodeResolver", () => { + let resolver: AgencyCodeResolver; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + imports: [PrismaModule], + providers: [AgencyCodeResolver, AgencyCodeService], + }).compile(); + + resolver = module.get(AgencyCodeResolver); + }); + + it("should be defined", () => { + expect(resolver).toBeDefined(); + }); +}); diff --git a/backend/src/agency_code/agency_code.resolver.ts b/backend/src/agency_code/agency_code.resolver.ts new file mode 100644 index 00000000..77d22e8a --- /dev/null +++ b/backend/src/agency_code/agency_code.resolver.ts @@ -0,0 +1,18 @@ +import { Resolver, Query, Args } from "@nestjs/graphql"; +import { AgencyCodeService } from "./agency_code.service"; +import { JwtRoleGuard } from "../auth/jwtrole.guard"; +import { UseGuards } from "@nestjs/common"; +import { Role } from "../enum/role.enum"; +import { Roles } from "../auth/decorators/roles.decorator"; + +@UseGuards(JwtRoleGuard) +@Resolver("AgencyCode") +export class AgencyCodeResolver { + constructor(private readonly agencyCodeService: AgencyCodeService) {} + + @Query("agencyCodes") + @Roles(Role.COS_OFFICER, Role.CEEB) + findAll() { + return this.agencyCodeService.findAll(); + } +} diff --git a/backend/src/agency_code/agency_code.service.spec.ts b/backend/src/agency_code/agency_code.service.spec.ts new file mode 100644 index 00000000..88454184 --- /dev/null +++ b/backend/src/agency_code/agency_code.service.spec.ts @@ -0,0 +1,20 @@ +import { Test, TestingModule } from "@nestjs/testing"; +import { AgencyCodeService } from "./agency_code.service"; +import { PrismaModule } from "nestjs-prisma"; + +describe("AgencyCodeService", () => { + let service: AgencyCodeService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + imports: [PrismaModule], + providers: [AgencyCodeService], + }).compile(); + + service = module.get(AgencyCodeService); + }); + + it("should be defined", () => { + expect(service).toBeDefined(); + }); +}); diff --git a/backend/src/agency_code/agency_code.service.ts b/backend/src/agency_code/agency_code.service.ts new file mode 100644 index 00000000..cdffe710 --- /dev/null +++ b/backend/src/agency_code/agency_code.service.ts @@ -0,0 +1,40 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "nestjs-prisma"; +import { AgencyCode } from "./entities/agency_code.entity"; + +@Injectable() +export class AgencyCodeService { + constructor(private prisma: PrismaService) {} + + async findAll() { + const prismaAgencyCodes = await this.prisma.agency_code.findMany({ + select: { + agency_code: true, + short_description: true, + long_description: true, + display_order: true, + active_ind: true, + }, + orderBy: [{ display_order: "asc" }], + }); + + const agencyCodes: AgencyCode[] = prismaAgencyCodes.map((prismaAgencyCodes) => ({ + agencyCode: prismaAgencyCodes.agency_code, + shortDescription: prismaAgencyCodes.short_description, + longDescription: prismaAgencyCodes.long_description, + displayOrder: prismaAgencyCodes.display_order, + activeIndicator: prismaAgencyCodes.active_ind, + })); + + return agencyCodes; + } + + findOne(id: string) { + return this.prisma.agency_code.findUnique({ + where: { + agency_code: id, + active_ind: true, + }, + }); + } +} diff --git a/backend/src/agency_code/entities/agency_code.entity.ts b/backend/src/agency_code/entities/agency_code.entity.ts new file mode 100644 index 00000000..29ac2844 --- /dev/null +++ b/backend/src/agency_code/entities/agency_code.entity.ts @@ -0,0 +1,7 @@ +export class AgencyCode { + agencyCode: string; + shortDescription: string; + longDescription: string; + displayOrder: number; + activeIndicator: boolean; +} diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 476b8442..20043019 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -30,6 +30,7 @@ import { NonComplianceCodeModule } from "./code-tables/non_compliance_code/non_c import { RationaleCodeModule } from "./code-tables/rationale_code/rationale_code.module"; import { SectorCodeModule } from "./code-tables/sector_code/sector_code.module"; import { CEEBDecisionActionModule } from "./ceeb_decision_action/ceeb_decision_action.module"; +import { AgencyCodeModule } from "./agency_code/agency_code.module"; @Module({ imports: [ @@ -41,6 +42,7 @@ import { CEEBDecisionActionModule } from "./ceeb_decision_action/ceeb_decision_a }), JwtAuthModule, AgeCodeModule, + AgencyCodeModule, EquipmentCodeModule, SexCodeModule, ThreatLevelCodeModule, diff --git a/backend/src/case_file/case_file.service.ts b/backend/src/case_file/case_file.service.ts index a9c9f7e0..014dbdb8 100644 --- a/backend/src/case_file/case_file.service.ts +++ b/backend/src/case_file/case_file.service.ts @@ -305,7 +305,7 @@ export class CaseFileService { discharge_code: true, rationale_code: true, inspection_number: true, - lead_agency: true, + lead_agency_code: true, non_compliance_decision_matrix_code: true, schedule_sector_xref: { select: { @@ -421,8 +421,8 @@ export class CaseFileService { if (decision[0].inspection_number) { record = { ...record, inspectionNumber: decision[0].inspection_number.toString() }; } - if (decision[0].lead_agency) { - record = { ...record, leadAgency: decision[0].lead_agency }; + if (decision[0].lead_agency_code) { + record = { ...record, leadAgency: decision[0].lead_agency_code }; } caseFile.decision = record; @@ -2495,7 +2495,7 @@ export class CaseFileService { } if (decision.leadAgency) { - record = { ...record, lead_agency: decision.leadAgency }; + record = { ...record, lead_agency_code: decision.leadAgency }; } const result = await db.decision.create({ @@ -2677,15 +2677,15 @@ export class CaseFileService { }; if (actionTaken === "FWDLEADAGN") { - data = { ...data, inspection_number: null, lead_agency: leadAgency }; + data = { ...data, inspection_number: null, lead_agency_code: leadAgency }; } if (actionTaken === "RESPREC") { - data = { ...data, lead_agency: null, inspection_number: parseInt(inspectionNumber) }; + data = { ...data, lead_agency_code: null, inspection_number: parseInt(inspectionNumber) }; } if (actionTaken !== "RESPREC" && actionTaken !== "FWDLEADAGN") { - data = { ...data, inspection_number: null, lead_agency: null }; + data = { ...data, inspection_number: null, lead_agency_code: null }; } const result = await db.decision.update({ diff --git a/migrations/sql/R__code-table-data.sql.sql b/migrations/sql/R__code-table-data.sql.sql index 0bc577f0..fe690c0f 100644 --- a/migrations/sql/R__code-table-data.sql.sql +++ b/migrations/sql/R__code-table-data.sql.sql @@ -21,6 +21,7 @@ values CURRENT_TIMESTAMP ) on conflict do nothing; +-- Fix display order update case_management.inaction_reason_code set display_order = 1 diff --git a/migrations/sql/R__insert_CEEB_decision_codes.sql b/migrations/sql/R__insert_CEEB_decision_codes.sql index 3427f321..74b36d91 100644 --- a/migrations/sql/R__insert_CEEB_decision_codes.sql +++ b/migrations/sql/R__insert_CEEB_decision_codes.sql @@ -1135,8 +1135,7 @@ VALUES CURRENT_TIMESTAMP, CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- -- INSERT schedule_code values @@ -1197,8 +1196,7 @@ VALUES CURRENT_TIMESTAMP, CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- -- INSERT new action_type_code values @@ -1220,8 +1218,7 @@ VALUES 'Y', CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- -- INSERT new action_code values @@ -1267,8 +1264,7 @@ VALUES 'Y', CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- -- INSERT new action_type_action_xref values @@ -1314,8 +1310,7 @@ VALUES 'Y', CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- -- INSERT non_compliance_decision_matrix_code values @@ -1409,8 +1404,7 @@ VALUES CURRENT_TIMESTAMP, CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- -- INSERT rationale values @@ -1460,8 +1454,7 @@ VALUES CURRENT_TIMESTAMP, CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- -- INSERT discharge_code values @@ -1566,35 +1559,295 @@ VALUES CURRENT_TIMESTAMP, CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- --- add new EPO agency code +-- INSERT data AGENCY_CODE -- insert into case_management.agency_code ( agency_code, short_description, long_description, + display_order, active_ind, create_user_id, - create_utc_timestamp, - update_user_id, - update_utc_timestamp + create_utc_timestamp + ) +values + ( + 'ALC', + 'Agricultural Land Commission', + 'Agricultural Land Commission', + 10, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'ENERGY', + 'BC Energy Regulator ', + 'BC Energy Regulator', + 20, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'PARKS', + 'BC Parks', + 'BC Parks', + 30, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'CEB', + 'Compliance and Enforcement Branch', + 'Compliance and Enforcement Branch', + 40, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp ) values ( 'EPO', 'CEEB', 'Compliance and Environmental Enforcement Branch', - true, + 50, + 'Y', CURRENT_USER, - CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP + ) ON CONFLICT DO NOTHING; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'ECCC', + 'Environment and Climate Change Canada', + 'Environment and Climate Change Canada', + 70, + 'Y', CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'EAO', + 'Environmental Assessment Office', + 'Environmental Assessment Office', + 80, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'FSIB', + 'Food Safety Inspection Branch', + 'Food Safety Inspection Branch', + 90, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'HEALTH', + 'Health Authority', + 'Health Authority', + 100, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'MHSED', + 'Mines Health, Safety and Enforcement Division', + 'Mines Health, Safety and Enforcement Division', + 110, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'MUNI', + 'Municipality / Regional District', + 'Municipality / Regional District', + 120, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'MOTI', + 'Transport Canada / MOTI', + 'Transport Canada / MOTI', + 130, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'OTHER', + 'Other', + 'Other', + 140, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +update case_management.agency_code +set + display_order = 60 +where + agency_code = 'COS'; + +update case_management.agency_code +set + display_order = 50 +where + agency_code = 'EPO'; -- -- add new ERS case_code @@ -1620,5 +1873,4 @@ values CURRENT_TIMESTAMP, CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; \ No newline at end of file + ) ON CONFLICT DO NOTHING; \ No newline at end of file diff --git a/migrations/sql/V1.28.0__CE-1035.sql b/migrations/sql/V1.28.0__CE-1035.sql new file mode 100644 index 00000000..377cea70 --- /dev/null +++ b/migrations/sql/V1.28.0__CE-1035.sql @@ -0,0 +1,9 @@ +ALTER TABLE case_management.decision +RENAME COLUMN lead_agency TO lead_agency_code; + +ALTER TABLE case_management.decision ADD CONSTRAINT FK_decision__lead_agency_code FOREIGN KEY (lead_agency_code) REFERENCES case_management.agency_code (agency_code); + +ALTER TABLE case_management.agency_code ADD display_order int4; + +--comment +COMMENT ON COLUMN case_management.agency_code.display_order is 'The order in which the values of the agency should be displayed when presented to a user in a list.'; \ No newline at end of file