Data Models
All database models are defined in src/models/ using Mongoose schemas. Every schema uses strict: false, which allows additional fields beyond those explicitly defined.
Models are registered via the barrel file at src/models/index.ts.
MOC (Management of Change)
Model name: moc
File: src/models/moc.ts
The central document that ties together all parts of a MOC lifecycle.
| Field | Type | Description |
|---|---|---|
serial_num | String (unique) | Auto-generated serial number in format {count}-{year} |
status | String | Current lifecycle step: "a" through "f", "decline", or "completed" |
department | String | Department where the change originates |
originator_id | ObjectId → User | User who initiated the MOC |
implementer_id | ObjectId → User | User assigned to implement the change |
approver_id | ObjectId → User | User assigned to approve the change |
verifier_id | ObjectId → User | User assigned to verify implementation |
hseq_id | ObjectId → User | HSEQ user assigned to review |
originator_form | ObjectId → originator | Part A form data |
implementer_form | ObjectId → implementer | Part B form data |
hseq_form | ObjectId → hseq | Part C form data |
approver_form | ObjectId → approver | Part D form data |
implementation | ObjectId → implementation | Part E form data |
verifier_form | ObjectId → verifier | Part F form data |
chat_id | ObjectId → chat | Associated chat room |
all_users | [ObjectId] → User | All users involved in this MOC |
risk_assessment | Object | Risk assessment attachments |
impact_assessment | [Object] | Impact assessment data (hazard categories) |
completed | Boolean | Whether the MOC has been fully closed |
Additional fields stored via strict: false:
logs— Array of audit log entries withuserId,action, and timestampaction_plan— Action plan data from Part Bmanual_plan— Manuals/drawings plan from Part BextentionsAndDeviations— Deviation and extension tracking objectscloned— Boolean indicating if this MOC was clonedisDeleted— Soft delete flagdepartment_serial— Department-specific serial number
User
Model name: User
File: src/models/users.ts
| Field | Type | Description |
|---|---|---|
name | String (required) | Full name |
email | String (required, unique) | Login email address |
password | String (required) | bcrypt-hashed password |
avatar | String | Profile picture URL |
access | String (required) | Access level (e.g., "full") |
department | String (required) | Department name (e.g., "hseq", "engineering") |
role | String | System role: "admin" or "user" |
mocs | [ObjectId] → moc | MOCs associated with this user |
Additional fields via strict: false:
onboarded— Boolean indicating onboarding completionsignature— Signature image URLdesignation— Job title/designation
PCR (Procedure Change Request)
Model name: PCR
File: src/models/pcr.ts
| Field | Type | Description |
|---|---|---|
originator_id | ObjectId → User | User who created the PCR |
form | Mixed | The originator form data (boolean fields, rich text, attachments) |
affectedParties | [Mixed] | Array of affected party entries with name, signature, comments |
signatures | [Mixed] | Array of signature entries with role, signature, date, comments |
serial_num | String | Auto-generated serial number |
status | String | "pending" or "finished" |
chatId | String | Associated chat room ID |
Additional fields via strict: false:
cloned— Boolean indicating if this PCR was clonedprevious_serial_num— Serial number of the PCR this was cloned from
Originator Form
Model name: originator
File: src/models/originator.ts
| Field | Type | Description |
|---|---|---|
originator_id | ObjectId → users | User who filled the form |
implementer_id | ObjectId → users | Assigned implementer |
moc | ObjectId → moc | Parent MOC |
approved | Boolean | Approval status (default: false) |
Form field data is stored in additional fields via strict: false.
Implementer Form
Model name: implementer
File: src/models/implementer.ts
| Field | Type | Description |
|---|---|---|
implementer_id | ObjectId → users | User who filled the form |
moc | ObjectId → moc | Parent MOC |
approver_id | ObjectId → users | Assigned approver |
approved | Boolean | Approval status (default: false) |
HSEQ Form
Model name: hseq
File: src/models/hseq.ts
| Field | Type | Description |
|---|---|---|
moc | ObjectId → moc | Parent MOC |
approved | Boolean | HSEQ approval status (default: false) |
Approver Form
Model name: approver
File: src/models/approver.ts
| Field | Type | Description |
|---|---|---|
moc | ObjectId → moc | Parent MOC |
approver_id | ObjectId → users | Approver user |
approved | Boolean | Approval status (default: false) |
Implementation
Model name: implementation
File: src/models/implementation.ts
| Field | Type | Description |
|---|---|---|
moc | ObjectId → moc | Parent MOC |
due_date | Date | Expected completion date |
actual_date | Date | Actual completion date |
status | String | Implementation status |
Verifier Form
Model name: verifier
File: src/models/verifier.ts
| Field | Type | Description |
|---|---|---|
moc | ObjectId → moc | Parent MOC |
verifier_id | ObjectId → users | Verifier user |
Chat
Model name: chat
File: src/models/chat.ts
| Field | Type | Description |
|---|---|---|
messages | [Object] | Array of message objects |
users | [ObjectId] → users | Participants |
Actions
Model name: actions
File: src/models/actions.ts
Tracks action items assigned to users within MOC workflows.
| Field | Type | Description |
|---|---|---|
moc_id | ObjectId → moc | Associated MOC |
user_id | ObjectId → users | Assigned user |
action_type | String | Enum: implementer_approve, implementer_impact_assessment, implementer_risk_assessment, implementer_form, hseq |
status | String | Enum: pending, approved, rejected, done |
mandatory | Boolean | Whether the action is required (default: false) |
category | String | Enum: moc, pcr |
Notifications
Model name: notifications
File: src/models/notifications.tsx
| Field | Type | Description |
|---|---|---|
user_emails | [String] | Recipient email addresses |
Additional fields stored via strict: false include read, finished, message content, and metadata.
Legacy Models
Old MOC (src/models/oldMoc.ts) and Old PCR (src/models/oldPcr.ts) store digitized records from paper-based archives. These have simpler schemas with serial number, title, originator info, and document attachments.
Entity Relationship Overview
User ──────────────────────────────────────────────────┐
│ │
├── originates ──▶ MOC │
├── implements ──▶ MOC │
├── approves ────▶ MOC │
├── reviews ─────▶ MOC (HSEQ) │
├── verifies ────▶ MOC │
│ │ │
│ ├── originator_form ──▶ Originator │
│ ├── implementer_form ─▶ Implementer│
│ ├── hseq_form ────────▶ HSEQ │
│ ├── approver_form ────▶ Approver │
│ ├── implementation ───▶ Implementation
│ ├── verifier_form ────▶ Verifier │
│ ├── chat_id ──────────▶ Chat │
│ └── actions ──────────▶ Actions │
│ │
└── originates ──▶ PCR │
├── affectedParties ──▶ [Users] ───┘
└── signatures ───────▶ [Role-based]