Skip to content

Commit

Permalink
Big Changes to data and FE
Browse files Browse the repository at this point in the history
  • Loading branch information
datajohnson committed Jul 2, 2024
1 parent 5fd6ef8 commit 5bb3d63
Show file tree
Hide file tree
Showing 63 changed files with 1,424 additions and 388 deletions.
1 change: 1 addition & 0 deletions api/@types/express/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Express {
store?: any;
oidc?: any;
auth?: any;
files: any | any[];

isAuthenticated(): boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const DB_CONFIG_DEV = {
},
};

export const MAIL_FROM = process.env.MAIL_FROM || "PMAPService@yukon.ca";
export const MAIL_FROM = process.env.MAIL_FROM || "SafetyPortal@yukon.ca";
export const MAIL_HOST = process.env.MAIL_HOST || "smtp.gov.yk.ca";
export const MAIL_PORT = process.env.MAIL_PORT || 25;
export const MAIL_USER = process.env.MAIL_USER || "";
Expand Down
13 changes: 13 additions & 0 deletions api/src/data/migrations/013.1.create-urgencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as knex from "knex";

export async function up(knex: knex.Knex) {
await knex.schema.createTable("urgencies", function (table) {
table.string("code", 8).primary().notNullable();
table.string("name", 256).notNullable();
table.string("description", 4000).nullable();
});
}

export async function down(knex: knex.Knex) {
await knex.schema.dropTable("urgencies");
}
9 changes: 2 additions & 7 deletions api/src/data/migrations/013.create-hazard-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ import * as knex from "knex";
export async function up(knex: knex.Knex) {
await knex.schema.createTable("hazard_types", function (table) {
table.increments("id").primary().notNullable();
table.integer("create_user_id").notNullable();
table.integer("searchable_user_id").nullable();
table.string("name", 256).notNullable();
table.string("description", 4000).nullable();
table.boolean("is_searchable").notNullable().defaultTo(true);
table.datetime("created_at").nullable().defaultTo(knex.fn.now());
table.date("searchable_on").nullable();
table.string("default_urgency_code").nullable();

table.foreign("create_user_id").references("users.id");
table.foreign("searchable_user_id").references("users.id");
table.foreign("default_urgency_code").references("urgencies.code");
});
}

Expand Down
47 changes: 25 additions & 22 deletions api/src/data/migrations/016.create-incidents.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import * as knex from "knex";

export async function up(knex: knex.Knex) {
await knex.schema.createTable("incidents", function(table) {
table.increments("id").primary().notNullable();
table.integer("proxy_role_type_id").nullable();
table.integer("incident_type_id").notNullable();
table.string("sensitivity_code", 8).notNullable();
table.string("status_code", 8).notNullable();
table.string("department_code", 8).notNullable();
table.string("reporting_person_email", 250).nullable();
table.string("supervisor_email", 250).nullable();
table.integer("proxy_user_id").nullable();
table.string("description", 4000).notNullable();
table.datetime("created_at").notNullable().defaultTo(knex.fn.now());
await knex.schema.createTable("incidents", function (table) {
table.increments("id").primary().notNullable();
table.integer("proxy_role_type_id").nullable();
table.integer("incident_type_id").notNullable();
table.string("sensitivity_code", 8).notNullable();
table.string("status_code", 8).notNullable();
table.string("department_code", 8).notNullable();
table.string("reporting_person_email", 250).nullable();
table.string("supervisor_email", 250).nullable();
table.integer("proxy_user_id").nullable();
table.string("description", 4000).notNullable();
table.datetime("created_at").notNullable().defaultTo(knex.fn.now());
table.datetime("reported_at").nullable();
table.string("urgency_code").notNullable();

table.foreign("sensitivity_code").references("sensitivities.code");
table.foreign("status_code").references("incident_statuses.code");
table.foreign("department_code").references("departments.code");
table.foreign("incident_type_id").references("incident_types.id");
table.foreign("proxy_user_id").references("users.id");
table.foreign("proxy_role_type_id").references("role_types.id");
});
};
table.foreign("sensitivity_code").references("sensitivities.code");
table.foreign("status_code").references("incident_statuses.code");
table.foreign("department_code").references("departments.code");
table.foreign("incident_type_id").references("incident_types.id");
table.foreign("proxy_user_id").references("users.id");
table.foreign("proxy_role_type_id").references("role_types.id");
table.foreign("urgency_code").references("urgencies.code");
});
}

export async function down(knex: knex.Knex) {
await knex.schema.dropTable("incidents");
};
await knex.schema.dropTable("incidents");
}
47 changes: 25 additions & 22 deletions api/src/data/migrations/017.create-hazards.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import * as knex from "knex";

export async function up(knex: knex.Knex) {
await knex.schema.createTable("hazards", function(table) {
table.increments("id").primary().notNullable();
table.integer("hazard_type_id").notNullable();
table.string("location_code", 8).nullable();
table.string("department_code", 8).nullable();
table.string("scope_code", 8).nullable();
table.string("status_code", 8).nullable();
table.string("sensitivity_code", 8).nullable();
table.string("description", 4000).nullable();
table.string("location_detail", 1000).nullable();
table.datetime("created_at").nullable().defaultTo(knex.fn.now());
table.integer("reopen_count").notNullable().defaultTo(0);
await knex.schema.createTable("hazards", function (table) {
table.increments("id").primary().notNullable();
table.integer("hazard_type_id").notNullable();
table.string("location_code", 8).nullable();
table.string("department_code", 8).nullable();
table.string("scope_code", 8).nullable();
table.string("status_code", 8).nullable();
table.string("sensitivity_code", 8).nullable();
table.string("description", 4000).nullable();
table.string("location_detail", 1000).nullable();
table.datetime("created_at").nullable().defaultTo(knex.fn.now());
table.datetime("reported_at").nullable()
table.integer("reopen_count").notNullable().defaultTo(0);
table.string("urgency_code").notNullable();

table.foreign("hazard_type_id").references("hazard_types.id");
table.foreign("location_code").references("locations.code");
table.foreign("department_code").references("departments.code");
table.foreign("scope_code").references("scopes.code");
table.foreign("sensitivity_code").references("sensitivities.code");
table.foreign("status_code").references("hazard_statuses.code");
});
};
table.foreign("hazard_type_id").references("hazard_types.id");
table.foreign("location_code").references("locations.code");
table.foreign("department_code").references("departments.code");
table.foreign("scope_code").references("scopes.code");
table.foreign("sensitivity_code").references("sensitivities.code");
table.foreign("status_code").references("hazard_statuses.code");
table.foreign("urgency_code").references("urgencies.code");
});
}

export async function down(knex: knex.Knex) {
await knex.schema.dropTable("hazards");
};
await knex.schema.dropTable("hazards");
}
59 changes: 30 additions & 29 deletions api/src/data/migrations/019.create-actions.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
import * as knex from "knex";

export async function up(knex: knex.Knex) {
await knex.schema.createTable("actions", function(table) {
table.increments("id").primary().notNullable();
table.integer("hazard_id").nullable();
table.integer("incident_id").nullable();
table.integer("creator_user_id").nullable();
table.integer("creator_role_type_id").nullable();
table.integer("actor_user_id").nullable();
table.integer("actor_user_email").nullable();
table.integer("actor_role_type_id").nullable();
table.datetime("created_at").notNullable().defaultTo(knex.fn.now());
table.datetime("modified_at").nullable().defaultTo(knex.fn.now());
table.datetime("due_date").nullable();
table.string("description", 4000).notNullable();
table.string("action_type_code", 8).notNullable();
table.string("sensitivity_code", 8).nullable();
table.string("status_code", 8).nullable();
await knex.schema.createTable("actions", function (table) {
table.increments("id").primary().notNullable();
table.integer("hazard_id").nullable();
table.integer("incident_id").nullable();
table.integer("creator_user_id").nullable();
table.integer("creator_role_type_id").nullable();
table.integer("actor_user_id").nullable();
table.string("actor_user_email", 250).nullable();
table.integer("actor_role_type_id").nullable();
table.datetime("created_at").notNullable().defaultTo(knex.fn.now());
table.datetime("modified_at").nullable().defaultTo(knex.fn.now());
table.datetime("due_date").nullable();
table.string("description", 4000).notNullable();
table.string("action_type_code", 8).notNullable();
table.string("sensitivity_code", 8).nullable();
table.string("status_code", 8).nullable();
table.string("notes", 4000).nullable();

table.foreign("hazard_id").references("hazards.id");
table.foreign("incident_id").references("incidents.id");
table.foreign("creator_user_id").references("users.id");
table.foreign("actor_user_id").references("users.id");
table.foreign("creator_role_type_id").references("role_types.id");
table.foreign("actor_role_type_id").references("role_types.id");
table.foreign("action_type_code").references("action_types.code");
table.foreign("sensitivity_code").references("sensitivities.code");
table.foreign("status_code").references("action_statuses.code");
});
};
table.foreign("hazard_id").references("hazards.id");
table.foreign("incident_id").references("incidents.id");
table.foreign("creator_user_id").references("users.id");
table.foreign("actor_user_id").references("users.id");
table.foreign("creator_role_type_id").references("role_types.id");
table.foreign("actor_role_type_id").references("role_types.id");
table.foreign("action_type_code").references("action_types.code");
table.foreign("sensitivity_code").references("sensitivities.code");
table.foreign("status_code").references("action_statuses.code");
});
}

export async function down(knex: knex.Knex) {
await knex.schema.dropTable("actions");
};
await knex.schema.dropTable("actions");
}
15 changes: 15 additions & 0 deletions api/src/data/migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ export class Migrator {
return res.json({ data: await this.listMigrations() });
});

this.migrationRouter.get("/seed/all", async (req: Request, res: Response) => {
try {
const result = await this.seedAll();
return res.json({ data: result });
} catch (err) {
console.error(err);
}
res.json({ data: "Seeding Failed" });
});

this.migrationRouter.get("/seed/:specific", async (req: Request, res: Response) => {
try {
const { specific } = req.params;
Expand Down Expand Up @@ -67,6 +77,11 @@ export class Migrator {
console.log(`-------- SEED ${specific} ---------`);
return db.seed.run({ specific, directory: join(__dirname, "seeds") });
}

async seedAll() {
console.log(`-------- SEED ALL ---------`);
return db.seed.run({ directory: join(__dirname, "seeds") });
}
}
const migrator = new Migrator();

Expand Down
9 changes: 6 additions & 3 deletions api/src/data/models/action-model.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
export interface Action {
id: number;
hazard_id: number;
id?: number;
hazard_id?: number;
incident_id?: number;
creator_user_id?: number;
creator_role_type_id?: number;
actor_user_id?: number;
actor_user_email?: string;
actor_role_type_id?: number;
created_at: Date;
modified_at?: Date;
due_date?: Date ;
due_date?: Date;
description: string;
action_type_code: string;
sensitivity_code?: string;
status_code?: string;
notes?: string;
}
7 changes: 7 additions & 0 deletions api/src/data/models/action-status-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ export interface ActionStatus {
name: string;
description?: string;
}

// This list matches the migration - changes should be made in both or
export class ActionStatuses {
static OPEN = { code: "Open", name: "Open" } as ActionStatus;
static BLOCKED = { code: "Blocked", name: "Blocked" } as ActionStatus;
static COMPLETE = { code: "Complete", name: "Complete" } as ActionStatus;
}
6 changes: 6 additions & 0 deletions api/src/data/models/action-type-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ export interface ActionType {
name: string;
description?: string;
}

// This list matches the migration - changes should be made in both or
export class ActionTypes {
static SYSTEM_GENERATED = { code: "System", name: "System Generated" } as ActionType;
static USER_GENERATED = { code: "User", name: "User Generated" } as ActionType;
}
13 changes: 8 additions & 5 deletions api/src/data/models/hazard-model.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Knex } from "knex";

export interface Hazard {
id: number;
id?: number;
hazard_type_id: number;
description?: string;
location_code?: string;
location_detail?: string;
department_code?: string;
scope_code?: string;
sensitivity_code?: string;
created_at: Date;
status_code?: string;
sensitivity_code?: string;
description?: string;
location_detail?: string;
created_at: Date | Knex.Raw<any>;
reopen_count: number;
urgency_code: string;
}
9 changes: 9 additions & 0 deletions api/src/data/models/hazard-status-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ export interface HazardStatus {
name: string;
description?: string;
}

// This list matches the migration - changes should be made in both or
export class HazardStatuses {
static OPEN = { code: "Open", name: "Open" } as HazardStatus;
static IN_PROGRESS = { code: "InPro", name: "In Progress" } as HazardStatus;
static DUPLICATE = { code: "Dup", name: "Duplicate" } as HazardStatus;
static NO_ACTION = { code: "NoAct", name: "No Action" } as HazardStatus;
static REMEDIATED = { code: "Remed", name: "Remediated" } as HazardStatus;
}
18 changes: 12 additions & 6 deletions api/src/data/models/hazard-type-model.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { Urgencies } from "./urgency-model";

export interface HazardType {
id: number;
create_user_id: number;
searchable_user_id?: number;
id?: number;
name: string;
description?: string;
is_searchable: boolean;
created_at?: Date;
searchable_on?: Date;
default_urgency_code?: string;
}

// This list matches the migration - changes should be made in both or
export class HazardTypes {
static ENVIRONMENTAL = { name: "Environ", default_urgency_code: Urgencies.MEDIUM.code } as HazardType;
static PHYSICAL = { name: "Phys", default_urgency_code: Urgencies.HIGH.code } as HazardType;
static PERSONAL = { name: "Pers", default_urgency_code: Urgencies.HIGH.code } as HazardType;
static JOB = { name: "Job", default_urgency_code: Urgencies.LOW.code } as HazardType;
}
6 changes: 6 additions & 0 deletions api/src/data/models/incident-hazard-model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Hazard } from "./hazard-model";
import { Incident } from "./incident-model";

export interface IncidentHazard {
id: number;
incident_id: number;
hazard_id: number;
incident_hazard_type_code: string;
priority_order: number;

incident?: Incident;
hazard?: Hazard;
}
6 changes: 6 additions & 0 deletions api/src/data/models/incident-hazard-type-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ export interface IncidentHazardType {
name: string;
description?: string;
}

// This list matches the migration - changes should be made in both or
export class IncidentHazardTypes {
static CONTRIBUTING_FACTOR = { code: "Contrib", name: "Contributing Factor" } as IncidentHazardType;
static CAUSE = { code: "Cause", name: "Cause" } as IncidentHazardType;
}
Loading

0 comments on commit 5bb3d63

Please sign in to comment.