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
waitingand triggers company creation workflow
- Sets initial status to
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
- Architecture Pattern: Singleton instance with
'default'ID managing all company records - Integration Points: Integrates with ApprovalManager, Workflow system, and MongoDB streaming
- Workflow Support: Full workflow integration with approval processes for all major operations
- Security Features: Program management user authentication with comprehensive permission system
- Data Management: Extends WorkflowCompatibleStateManager for advanced state management
- External Integrations: MongoDB streaming capabilities for data synchronization
- Performance Features: Efficient search, filtering, and pagination support
- 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: