Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Company

Overview

The Company class manages company entities and their relationships within the system, serving as a central registry for organizations and their configurations.

General Purpose:

  • Manages company creation, updates, and status changes with workflow approval integration
  • Maintains company group relationships and HR contact information
  • Defines member type eligibility and dependant management policies with runtime validation
  • Provides data streaming capabilities to MongoDB for external synchronization
  • Singleton instance with 'default' ID managing all company records

Data Structure

State Schema

interface CompanyState {
  private: {
    companies: Company[]
  }
  public: object
}

interface Company {
  id: string
  name: string
  description?: string
  companyGroupId: string
  hrContact: HRContact
  status: CompanyStatus
  createdBy: Actor
  createdAt: Date
  updatedAt: Date
  eligibleMemberTypes: string[]
  memberSubTypes: CompanyMemberSubTypes[]
  maxFreeDependants: number
}

Enums and Types

enum CompanyStatus {
  ACTIVE = 'active',
  INACTIVE = 'inactive',
  PENDING = 'pending'
}

enum CompanyEvents {
  COMPANY_CREATE = 'company_create',
  UPDATE_COMPANY = 'update_company',
  UPDATE_COMPANY_STATUS = 'update_company_status'
}

Additional Structures

interface HRContact {
  name: string
  email: string
}

interface CompanyMemberSubTypes {
  memberSubTypeId: string
  maxDependants: number
}

interface Actor {
  id: string
}

Core Functionality

Main Feature Groups

  • Company Lifecycle Management: Create, update, and manage company information with workflow integration
  • Status Management: Control company status transitions (waiting → active/inactive) through approval workflows
  • Search and Filtering: Search capabilities by name, description, status, and company group
  • Member Type Configuration: Define eligible member types and dependant policies for each company
  • Member Type Validation: Validate member type eligibility during member creation and updates
  • Data Synchronization: Stream company data to MongoDB for external system integration

Workflow Integration

The Company class extends WorkflowCompatibleStateManager and integrates with the workflow system:

  • Status Transitions: Workflow rules manage company status changes from pending to active/inactive
  • Events: Company creation, updates, and status changes trigger workflow processing
  • Approval Integration: All significant operations go through approval workflows before final completion
  • Business Rules: Workflow configuration defines approval requirements and status transition logic

API Methods

Company Management

  • createCompany (WRITE) - Create a new company with workflow approval
    • Sets initial status to waiting and triggers company creation workflow
  • updateCompany (WRITE) - Update existing company information
    • Requires company existence validation and triggers update workflow
  • updateCompanyStatus (WRITE) - Update company status
    • Manages status transitions through workflow rules

Company Information

  • getCompany (READ) - Retrieve company details by ID
    • Accessible by program management users and Member class for member type validation
  • listCompanies (READ) - List companies with filtering and pagination
    • Supports filtering by status, company group, and search terms
    • Includes pagination with configurable page size and limits

Approval Operations

  • approveCompany (QUEUED_WRITE) - Process approval workflows
    • Applies JSON patches from approval records and triggers MongoDB streaming
  • streamCompany (READ) - Manual data streaming to MongoDB
    • Synchronizes specific company data with external MongoDB collections by company ID

Method Types:

  • WRITE - Sync state mutation (1-30s)
  • READ - Sync state access (1-30s)
  • QUEUED_WRITE - Async state mutation (1-890s)
  • STATIC - Stateless utility

Key Features

  1. Architecture Pattern: Singleton instance with 'default' ID managing all company records
  2. Integration Points: Integrates with ApprovalManager, Workflow system, and MongoDB streaming
  3. Workflow Support: Full workflow integration with approval processes for all major operations
  4. Security Features: Program management user authentication with comprehensive permission system
  5. Data Management: Extends WorkflowCompatibleStateManager for advanced state management
  6. External Integrations: MongoDB streaming capabilities for data synchronization
  7. Performance Features: Efficient search, filtering, and pagination support
  8. Audit/Logging: Complete activity tracking through workflow system and actor-based operations

Class Relations

The following diagram illustrates how Company integrates with other system components:

Company Relations