Skip to content

Commit

Permalink
fix: Ce 1054 (#92)
Browse files Browse the repository at this point in the history
Co-authored-by: afwilcox <[email protected]>
  • Loading branch information
gregorylavery and afwilcox authored Sep 27, 2024
1 parent e8e9dd7 commit 3ddcbc2
Show file tree
Hide file tree
Showing 13 changed files with 5,120 additions and 1,863 deletions.
11 changes: 11 additions & 0 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@ model schedule_sector_xref {
decision decision[]
schedule_code_schedule_sector_xref_schedule_codeToschedule_code schedule_code @relation("schedule_sector_xref_schedule_codeToschedule_code", fields: [schedule_code], references: [schedule_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_schedule_sector_xref__schedule_code")
sector_code_schedule_sector_xref_sector_codeTosector_code sector_code @relation("schedule_sector_xref_sector_codeTosector_code", fields: [sector_code], references: [sector_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_schedule_sector_xref__sector_code")
@@unique([schedule_code, sector_code], map: "uk_schedule_sector_xref__schedule_sector")
}

/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
Expand Down Expand Up @@ -602,3 +604,12 @@ model site_h {
operation_executed_at DateTime @default(now()) @db.Timestamp(6)
data_after_executed_operation Json?
}

/// This table contains check constraints and requires additional setup for migrations. Visit https://pris.ly/d/check-constraints for more info.
model spatial_ref_sys {
srid Int @id
auth_name String? @db.VarChar(256)
auth_srid Int?
srtext String? @db.VarChar(2048)
proj4text String? @db.VarChar(2048)
}
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 { 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";
import { ScheduleSectorXrefModule } from "./schedule_sector_xref/schedule_sector_xref.module";

@Module({
imports: [
Expand Down Expand Up @@ -61,6 +62,7 @@ import { AgencyCodeModule } from "./agency_code/agency_code.module";
NonComplianceCodeModule,
SectorCodeModule,
CEEBDecisionActionModule,
ScheduleSectorXrefModule,
],
controllers: [AppController],
providers: [AppService, DateScalar],
Expand Down
77 changes: 40 additions & 37 deletions backend/src/case_file/case_file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2504,14 +2504,15 @@ export class CaseFileService {

return result?.decision_guid;
} catch (exception) {
throw new GraphQLError("Exception occurred. See server log for details", exception);
const { message } = exception;
throw new Error("Exception occurred in _addDecision. See server log for details", message);
}
};

//--
//-- creates a schedule/sector xref record and returns the schedule_sector_xref_guid
//-- finds a schedule/sector xref record and returns the schedule_sector_xref_guid
//--
const _addWdrXref = async (
const _findWdrXref = async (
db: Omit<
PrismaClient<Prisma.PrismaClientOptions, never, DefaultArgs>,
"$connect" | "$disconnect" | "$on" | "$transaction" | "$use" | "$extends"
Expand All @@ -2522,24 +2523,20 @@ export class CaseFileService {
try {
const { sector, schedule } = decision;

let record: any = {
schedule_sector_xref_guid: randomUUID(),
sector_code: sector,
schedule_code: schedule,
active_ind: true,
create_user_id: userId,
update_user_id: userId,
create_utc_timestamp: new Date(),
update_utc_timestamp: new Date(),
};

const result = await db.schedule_sector_xref.create({
data: record,
let scheduleSectorXref = await this.prisma.schedule_sector_xref.findFirstOrThrow({
where: {
schedule_code: schedule,
sector_code: sector,
},
select: {
schedule_sector_xref_guid: true,
},
});

return result?.schedule_sector_xref_guid;
return scheduleSectorXref;
} catch (exception) {
throw new GraphQLError("Exception occurred. See server log for details", exception);
const { message } = exception;
throw new Error("Exception occurred in _findWdrXref. See server log for details", message);
}
};

Expand Down Expand Up @@ -2580,7 +2577,8 @@ export class CaseFileService {

return result?.action_guid;
} catch (exception) {
throw new GraphQLError("Exception occurred. See server log for details", exception);
const { message } = exception;
throw new Error("Exception occurred in _applyAction. See server log for details", message);
}
};

Expand All @@ -2599,11 +2597,11 @@ export class CaseFileService {
caseFileId = await this.createCase(db, caseInput);
}

//-- create sector/schedule xref
const xref = await _addWdrXref(db, decision, createUserId);
//-- find the sector/schedule xref entry
const xref = await _findWdrXref(db, decision, createUserId);

//-- add decision
const decsionId = await _addDecision(db, caseFileId, decision, xref, createUserId);
const decsionId = await _addDecision(db, caseFileId, decision, xref.schedule_sector_xref_guid, createUserId);

//-- apply action
if (decision.actionTaken && decision.assignedTo) {
Expand All @@ -2620,8 +2618,8 @@ export class CaseFileService {

return result;
} catch (error) {
console.log("exception: unable to create wildlife ", error);
throw new GraphQLError("Exception occurred. See server log for details", {});
const { message } = error;
throw new Error("Exception occurred in _findWdrXref. See server log for details", message);
}
};

Expand Down Expand Up @@ -2701,7 +2699,7 @@ export class CaseFileService {
};

//--
//-- updates an existing sector/schedule xref record and returns the xref
//-- updates an existing decision with new sector/schedule xref guid
//--
const _updateWdrXref = async (
db: Omit<
Expand All @@ -2717,15 +2715,26 @@ export class CaseFileService {
const { sector, schedule } = decision;

let data: any = {
schedule_sector_xref_guid: id,
sector_code: sector,
schedule_code: schedule,
decision_guid: id,
update_user_id: updateUserId,
update_utc_timestamp: current,
};

const result = db.schedule_sector_xref.update({
where: { schedule_sector_xref_guid: id },
let scheduleSectorXref = await this.prisma.schedule_sector_xref.findFirstOrThrow({
where: {
schedule_code: decision.schedule,
sector_code: decision.sector,
},
select: {
schedule_sector_xref_guid: true,
},
});

if (scheduleSectorXref) {
data = { ...data, schedule_sector_xref_guid: scheduleSectorXref.schedule_sector_xref_guid };
}
const result = db.decision.update({
where: { decision_guid: id },
data,
});

Expand Down Expand Up @@ -2802,13 +2811,7 @@ export class CaseFileService {

//-- if the update was successful update the sector/schedule xref
//-- and action taken
const xrefResult = await _updateWdrXref(
db,
source.schedule_sector_xref_guid,
decision,
updateUserId,
current,
);
const xrefResult = await _updateWdrXref(db, update.decision_guid, decision, updateUserId, current);

//-- make sure that there is an action to update first
//-- otherwise create a new action
Expand Down
1 change: 1 addition & 0 deletions backend/src/code-tables/sector_code/sector_code.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class SectorCodeService {
display_order: true,
active_ind: true,
},
orderBy: [{ display_order: "asc" }],
});

return codes.map(({ sector_code, short_description, long_description, display_order, active_ind }) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class ScheduleSectorXref {
sectorCode: string;
scheduleCode: string;
shortDescription: string;
longDescription: string;
activeIndicator: boolean;
}
12 changes: 12 additions & 0 deletions backend/src/schedule_sector_xref/schedule_sector_xref.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type ScheduleSectorXref {
sectorCode: String
scheduleCode: String
shortDescription: String
longDescription: String
displayOrder: Int
activeIndicator: Boolean
}

type Query {
scheduleSectorXrefs: [ScheduleSectorXref]!
}
10 changes: 10 additions & 0 deletions backend/src/schedule_sector_xref/schedule_sector_xref.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from "@nestjs/common";
import { PrismaModule } from "nestjs-prisma";
import { ScheduleSectorXrefService } from "./schedule_sector_xref.service";
import { ScheduleSectorXrefResolver } from "./schedule_sector_xref.resolver";

@Module({
imports: [PrismaModule],
providers: [ScheduleSectorXrefResolver, ScheduleSectorXrefService],
})
export class ScheduleSectorXrefModule {}
19 changes: 19 additions & 0 deletions backend/src/schedule_sector_xref/schedule_sector_xref.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Resolver, Query, Args } from "@nestjs/graphql";
import { UseGuards } from "@nestjs/common";
import { JwtRoleGuard } from "src/auth/jwtrole.guard";
import { Roles } from "src/auth/decorators/roles.decorator";
import { Role } from "src/enum/role.enum";
import { ScheduleSectorXrefService } from "./schedule_sector_xref.service";
import { JwtAuthGuard } from "src/auth/jwtauth.guard";

@UseGuards(JwtAuthGuard, JwtRoleGuard)
@Resolver("ScheduleSectorXref")
export class ScheduleSectorXrefResolver {
constructor(private readonly service: ScheduleSectorXrefService) {}

@Query("scheduleSectorXrefs")
@Roles(Role.CEEB, Role.COS_OFFICER)
findAll() {
return this.service.findAll();
}
}
46 changes: 46 additions & 0 deletions backend/src/schedule_sector_xref/schedule_sector_xref.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Injectable } from "@nestjs/common";
import { PrismaService } from "nestjs-prisma";
import { ScheduleSectorXref } from "./entities/schedule_sector_xref.entity";

@Injectable()
export class ScheduleSectorXrefService {
constructor(private prisma: PrismaService) {}

findAll = async (): Promise<Array<ScheduleSectorXref>> => {
const codes = await this.prisma.schedule_sector_xref.findMany({
select: {
sector_code: true,
schedule_code: true,
sector_code_schedule_sector_xref_sector_codeTosector_code: {
select: {
long_description: true,
short_description: true,
},
},
active_ind: true,
},
orderBy: [
{
sector_code_schedule_sector_xref_sector_codeTosector_code: {
display_order: "asc",
},
},
],
});

return codes.map(
({
sector_code,
schedule_code,
sector_code_schedule_sector_xref_sector_codeTosector_code: { long_description, short_description },
active_ind,
}) => ({
sectorCode: sector_code,
scheduleCode: schedule_code,
longDescription: long_description,
shortDescription: short_description,
activeIndicator: active_ind,
}),
);
};
}
Loading

0 comments on commit 3ddcbc2

Please sign in to comment.