Skip to content

Repository files navigation

@girp/database-models

Single Source of Truth for GIRP (Guided Incident Response Platform) data structures. Contains the shared Mongoose models used across all GIRP microservices to keep data structures consistent.

Installation

npm install @girp/database-models

Requires Node.js >= 20 and MongoDB via Mongoose 8.

Usage

const { TicketModel, Playbook, FormResult } = require("@girp/database-models");

const openTickets = await TicketModel.find({ state: "open" });

Exported models

Model Purpose
Playbook Playbook / form definitions built with the GIRP Formbuilder
PlaybookVersion Versioned playbook snapshots
FormSession In-progress form fill sessions
FormResult Completed form submissions
TicketModel Incident tickets
UserModel User accounts
UserPreferences Per-user settings
ApiToken API access tokens
CounterModel Sequence counters (auto-increment IDs)
Settings Global application settings

The models register themselves on the default Mongoose connection — call mongoose.connect(...) in your service before using them.

Note: once the connection is established, the ticket and user models backfill missing createdAt/updatedAt/roles fields on existing documents (one idempotent updateMany each). This keeps documents created by older GIRP versions queryable.

Ticket changelog & timeline

TicketModel automatically records field changes in an embedded changelog. Pass the acting user so entries are attributed:

// a) save() path — set the actor via $locals
const ticket = await TicketModel.findById(id);
ticket.$locals.userId = req.user._id;
ticket.state = "mitigation";
await ticket.save();

// b) query update path — pass the actor as a query option
await TicketModel.findByIdAndUpdate(
  id,
  {
    $set: { state: "closed" },
    $push: { comments: { comment_content: "Done", author: req.user._id } },
  },
  { new: true, runValidators: true, userId: req.user._id }
);

// c) fetch the merged comment/changelog timeline (populated, newest first)
const timeline = await TicketModel.getTimelineById(id, { populate: true, order: "desc" });

License

Licensed under the Sustainable Use License — see LICENSE.md.

About

No description, website, or topics provided.

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages