Skip to content

Commit

Permalink
feat: CE-1035 update lead agency list in CEEB decision (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scarlett-Truong authored Sep 26, 2024
1 parent 849f152 commit eba65a9
Show file tree
Hide file tree
Showing 13 changed files with 426 additions and 34 deletions.
3 changes: 2 additions & 1 deletion backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions backend/src/agency_code/agency_code.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type AgencyCode {
agencyCode: String
shortDescription: String
longDescription: String
displayOrder: Int
activeIndicator: Boolean
}

type Query {
agencyCodes: [AgencyCode]!
}
10 changes: 10 additions & 0 deletions backend/src/agency_code/agency_code.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
21 changes: 21 additions & 0 deletions backend/src/agency_code/agency_code.resolver.spec.ts
Original file line number Diff line number Diff line change
@@ -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>(AgencyCodeResolver);
});

it("should be defined", () => {
expect(resolver).toBeDefined();
});
});
18 changes: 18 additions & 0 deletions backend/src/agency_code/agency_code.resolver.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
20 changes: 20 additions & 0 deletions backend/src/agency_code/agency_code.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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>(AgencyCodeService);
});

it("should be defined", () => {
expect(service).toBeDefined();
});
});
40 changes: 40 additions & 0 deletions backend/src/agency_code/agency_code.service.ts
Original file line number Diff line number Diff line change
@@ -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,
},
});
}
}
7 changes: 7 additions & 0 deletions backend/src/agency_code/entities/agency_code.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class AgencyCode {
agencyCode: string;
shortDescription: string;
longDescription: string;
displayOrder: number;
activeIndicator: boolean;
}
2 changes: 2 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -41,6 +42,7 @@ import { CEEBDecisionActionModule } from "./ceeb_decision_action/ceeb_decision_a
}),
JwtAuthModule,
AgeCodeModule,
AgencyCodeModule,
EquipmentCodeModule,
SexCodeModule,
ThreatLevelCodeModule,
Expand Down
14 changes: 7 additions & 7 deletions backend/src/case_file/case_file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions migrations/sql/R__code-table-data.sql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ values
CURRENT_TIMESTAMP
) on conflict do nothing;

-- Fix display order
update case_management.inaction_reason_code
set
display_order = 1
Expand Down
Loading

0 comments on commit eba65a9

Please sign in to comment.