Skip to content

Commit

Permalink
Merge pull request #48 from icefoganalytics/main
Browse files Browse the repository at this point in the history
Fixes for Oracle
  • Loading branch information
datajohnson authored Jan 16, 2025
2 parents b0f2bf6 + 4388514 commit 4d3a5f9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion api/src/data/migrations/031.create-investigations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function up(knex: knex.Knex) {
table.integer("hazard_id").nullable();
table.integer("incident_id").nullable();
table.integer("creator_user_id").nullable();
table.json("investigation_data").nullable();
table.text("investigation_data").nullable();

table.foreign("hazard_id").references("hazards.id");
table.foreign("incident_id").references("incidents.id");
Expand Down
41 changes: 17 additions & 24 deletions api/src/routes/report-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
UserRole,
} from "../data/models";
import { InsertableDate } from "../utils/formatters";
import { DateTime } from "luxon";

export const reportRouter = express.Router();
const db = new IncidentService();
Expand Down Expand Up @@ -72,16 +73,10 @@ reportRouter.post("/:id/investigation", async (req: Request, res: Response) => {
investigation_data.completed_on = new Date().toISOString();
investigation_data.completed_by = req.user.display_name;
investigation_data.completed_by_ud = req.user.id;

console.log("investigation_data", investigation_data);
const jsonString = JSON.stringify(investigation_data);

console.log("jsonString", jsonString);

await knex("investigations").insert({ incident_id: id, investigation_data: jsonString });

//await knex("incidents").where({ id }).update({ description, investigation_notes, additional_description });

return res.json({ data: {}, messages: [{ variant: "success", text: "Incident Saved" }] });
});

Expand Down Expand Up @@ -153,15 +148,13 @@ reportRouter.post("/", async (req: Request, res: Response) => {
description,
location_detail,
reopen_count: 0,
created_at: InsertableDate(new Date().toISOString()),
created_at: InsertableDate(DateTime.utc().toISO()),
reported_at: InsertableDate(date),
urgency_code: urgency,
} as Hazard;

console.log("supervisor_alt_email", supervisor_alt_email);

const incident = {
created_at: InsertableDate(new Date().toISOString()),
created_at: InsertableDate(DateTime.utc().toISO()),
reported_at: InsertableDate(date),
description,
department_code: department.code,
Expand Down Expand Up @@ -190,16 +183,16 @@ reportRouter.post("/", async (req: Request, res: Response) => {

await trx("incident_hazards").insert(link);

const basicSteps = [
"Incident Reported",
"Investigation",
"Control Plan",
"Controls Implemented",
"Employee Notification",
];
let steps = new Array<string>();

if (eventType == "hazard") {
steps = ["Hazard Identified", "Assessment of Hazard", "Control the Hazard", "Employee Notification"];
} else {
steps = ["Incident Reported", "Investigation", "Control Plan", "Controls Implemented", "Employee Notification"];
}

for (let i = 1; i <= basicSteps.length; i++) {
const step_title = basicSteps[i - 1];
for (let i = 1; i <= steps.length; i++) {
const step_title = steps[i - 1];

const step = {
incident_id: insertedIncidentId,
Expand All @@ -209,7 +202,7 @@ reportRouter.post("/", async (req: Request, res: Response) => {
} as IncidentStep;

if (i == 1) {
(step as any).complete_date = InsertableDate(new Date().toISOString());
(step as any).complete_date = InsertableDate(DateTime.utc().toISO());
step.complete_name = req.user.display_name;
step.complete_user_id = req.user.id;
}
Expand All @@ -230,7 +223,7 @@ reportRouter.post("/", async (req: Request, res: Response) => {
file_type: file.mimetype,
file_size: file.size,
file: file.data,
added_date: InsertableDate(new Date().toISOString()),
added_date: InsertableDate(DateTime.utc().toISO()),
} as IncidentAttachment;

await trx("incident_attachments").insert(attachment);
Expand Down Expand Up @@ -282,7 +275,7 @@ reportRouter.put("/:id/step/:step_id/:operation", async (req: Request, res: Resp
.where({ incident_id: id, id: step_id })
.update({
complete_name: req.user.display_name,
complete_date: InsertableDate(new Date().toISOString()),
complete_date: InsertableDate(DateTime.utc().toISO()),
complete_user_id: req.user.id,
});
} else if (operation == "revert") {
Expand Down Expand Up @@ -322,7 +315,7 @@ reportRouter.post("/:id/action", async (req: Request, res: Response) => {

const action = {
incident_id: parseInt(id),
created_at: InsertableDate(new Date().toISOString()),
created_at: InsertableDate(DateTime.utc().toISO()),
description,
notes,
action_type_code: ActionTypes.USER_GENERATED.code,
Expand Down Expand Up @@ -397,7 +390,7 @@ reportRouter.put("/:id/action/:action_id/:operation", async (req: Request, res:
await knex("actions")
.where({ incident_id: id, id: action_id })
.update({
complete_date: InsertableDate(new Date().toISOString()),
complete_date: InsertableDate(DateTime.utc().toISO()),
complete_name: req.user.display_name,
complete_user_id: req.user.id,
});
Expand Down
5 changes: 5 additions & 0 deletions api/src/services/incident-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export class IncidentService {
item.steps = await db("incident_steps").where({ incident_id: item.id }).orderBy("order");
item.actions = await db("actions").where({ incident_id: item.id }).orderBy("due_date").orderBy("id");
item.investigation = await db("investigations").where({ incident_id: item.id }).first();

if (item.investigation) {
item.investigation.investigation_data = JSON.parse(item.investigation.investigation_data);
}

item.hazards = await db("incident_hazards")
.where({ incident_id: item.id })
.innerJoin("incident_hazard_types", "incident_hazards.incident_hazard_type_code", "incident_hazard_types.code")
Expand Down

0 comments on commit 4d3a5f9

Please sign in to comment.