Skip to main content

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.

FieldTypeDescription
serial_numString (unique)Auto-generated serial number in format {count}-{year}
statusStringCurrent lifecycle step: "a" through "f", "decline", or "completed"
departmentStringDepartment where the change originates
originator_idObjectId → UserUser who initiated the MOC
implementer_idObjectId → UserUser assigned to implement the change
approver_idObjectId → UserUser assigned to approve the change
verifier_idObjectId → UserUser assigned to verify implementation
hseq_idObjectId → UserHSEQ user assigned to review
originator_formObjectId → originatorPart A form data
implementer_formObjectId → implementerPart B form data
hseq_formObjectId → hseqPart C form data
approver_formObjectId → approverPart D form data
implementationObjectId → implementationPart E form data
verifier_formObjectId → verifierPart F form data
chat_idObjectId → chatAssociated chat room
all_users[ObjectId] → UserAll users involved in this MOC
risk_assessmentObjectRisk assessment attachments
impact_assessment[Object]Impact assessment data (hazard categories)
completedBooleanWhether the MOC has been fully closed

Additional fields stored via strict: false:

  • logs — Array of audit log entries with userId, action, and timestamp
  • action_plan — Action plan data from Part B
  • manual_plan — Manuals/drawings plan from Part B
  • extentionsAndDeviations — Deviation and extension tracking objects
  • cloned — Boolean indicating if this MOC was cloned
  • isDeleted — Soft delete flag
  • department_serial — Department-specific serial number

User

Model name: User File: src/models/users.ts

FieldTypeDescription
nameString (required)Full name
emailString (required, unique)Login email address
passwordString (required)bcrypt-hashed password
avatarStringProfile picture URL
accessString (required)Access level (e.g., "full")
departmentString (required)Department name (e.g., "hseq", "engineering")
roleStringSystem role: "admin" or "user"
mocs[ObjectId] → mocMOCs associated with this user

Additional fields via strict: false:

  • onboarded — Boolean indicating onboarding completion
  • signature — Signature image URL
  • designation — Job title/designation

PCR (Procedure Change Request)

Model name: PCR File: src/models/pcr.ts

FieldTypeDescription
originator_idObjectId → UserUser who created the PCR
formMixedThe 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_numStringAuto-generated serial number
statusString"pending" or "finished"
chatIdStringAssociated chat room ID

Additional fields via strict: false:

  • cloned — Boolean indicating if this PCR was cloned
  • previous_serial_num — Serial number of the PCR this was cloned from

Originator Form

Model name: originator File: src/models/originator.ts

FieldTypeDescription
originator_idObjectId → usersUser who filled the form
implementer_idObjectId → usersAssigned implementer
mocObjectId → mocParent MOC
approvedBooleanApproval status (default: false)

Form field data is stored in additional fields via strict: false.

Implementer Form

Model name: implementer File: src/models/implementer.ts

FieldTypeDescription
implementer_idObjectId → usersUser who filled the form
mocObjectId → mocParent MOC
approver_idObjectId → usersAssigned approver
approvedBooleanApproval status (default: false)

HSEQ Form

Model name: hseq File: src/models/hseq.ts

FieldTypeDescription
mocObjectId → mocParent MOC
approvedBooleanHSEQ approval status (default: false)

Approver Form

Model name: approver File: src/models/approver.ts

FieldTypeDescription
mocObjectId → mocParent MOC
approver_idObjectId → usersApprover user
approvedBooleanApproval status (default: false)

Implementation

Model name: implementation File: src/models/implementation.ts

FieldTypeDescription
mocObjectId → mocParent MOC
due_dateDateExpected completion date
actual_dateDateActual completion date
statusStringImplementation status

Verifier Form

Model name: verifier File: src/models/verifier.ts

FieldTypeDescription
mocObjectId → mocParent MOC
verifier_idObjectId → usersVerifier user

Chat

Model name: chat File: src/models/chat.ts

FieldTypeDescription
messages[Object]Array of message objects
users[ObjectId] → usersParticipants

Actions

Model name: actions File: src/models/actions.ts

Tracks action items assigned to users within MOC workflows.

FieldTypeDescription
moc_idObjectId → mocAssociated MOC
user_idObjectId → usersAssigned user
action_typeStringEnum: implementer_approve, implementer_impact_assessment, implementer_risk_assessment, implementer_form, hseq
statusStringEnum: pending, approved, rejected, done
mandatoryBooleanWhether the action is required (default: false)
categoryStringEnum: moc, pcr

Notifications

Model name: notifications File: src/models/notifications.tsx

FieldTypeDescription
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]