Use Case Documentation
Overview
The service management module implements comprehensive business logic for managing bookable services within the Bee O'clock platform. The module follows Clean Architecture principles and CQRS pattern to separate command and query responsibilities while maintaining clear business logic boundaries.
Core Use Cases
1. Get Paged Services Use Case
Purpose: Retrieves a paginated list of services for a tenant with optional search and filtering capabilities.
Location: GetPagedServicesUseCase
Input Parameters:
ctx: TenantActorContext- Context with tenant and actor informationpagination: ServicePaginationDto- Pagination and search parameters
Business Logic:
Validates actor permissions (
READ_SERVICE)Applies search phrase filtering if provided
Executes paginated query through CQRS query bus
Returns paginated result with services and metadata
Search Functionality:
Searches across service titles and descriptions
Supports multilingual content search
Case-insensitive phrase matching
Efficient indexing for performance
Output: PaginationResponseDto<ServiceDto>
2. Get Service by ID Use Case
Purpose: Retrieves detailed information about a specific service including all configuration and presentation data.
Location: GetServiceUseCase
Input Parameters:
ctx: TenantActorContext- Context with tenant and actor informationserviceId: string- Unique identifier of the service
Business Logic:
Validates actor permissions (
READ_SERVICE)Retrieves service from repository through query bus
Throws
ServiceNotFoundExceptionif service not foundReturns complete service data with all related information
Data Population:
Populates language versions
Includes duration and pricing options
Loads presentation media
Includes scheduling information
Output: ServiceDto
3. Create Service Use Case
Purpose: Creates a new service with comprehensive validation and configuration setup.
Location: CreateServiceUseCase
Input Parameters:
ctx: TenantActorContext- Context with tenant and actor informationservice: ServiceDto- Service data to create
Business Logic:
Validates actor permissions (
CREATE_SERVICE)Validates service data structure and content
Ensures language versions are provided
Validates duration versions and pricing
Checks business rules compliance
Creates service through command bus
Publishes service created event
Returns created service ID
Validation Rules:
At least one language version required
Valid duration and pricing configuration
Proper color format validation
Media file format validation
Business-specific constraints
Event Publishing:
Emits
ServiceCreatedEventfor downstream processingTriggers cache invalidation
Notifies integration systems
Output: string (Service ID)
4. Update Service Use Case
Purpose: Updates an existing service with comprehensive validation and change tracking.
Location: UpdateServiceUseCase
Input Parameters:
ctx: TenantActorContext- Context with tenant and actor informationserviceId: string- ID of service to updateupdate: ServiceDto- Updated service data
Business Logic:
Validates actor permissions (
EDIT_SERVICE)Retrieves existing service for comparison
Validates update data and business rules
Ensures critical data integrity
Executes update through command bus
Publishes service updated event
Handles cache invalidation
Update Validation:
Cannot remove all language versions
Cannot remove all duration versions
Validates pricing changes
Ensures media consistency
Checks scheduling conflicts
Change Tracking:
Maintains audit trail
Tracks field-level changes
Preserves historical data
Enables rollback capabilities
Output: void
5. Delete Service Use Case
Purpose: Safely deletes a service with comprehensive validation and dependency checking.
Location: DeleteServiceUseCase
Input Parameters:
ctx: TenantActorContext- Context with tenant and actor informationserviceId: string- ID of service to delete
Business Logic:
Validates actor permissions (
DELETE_SERVICE)Checks service exists
Validates no active orders reference service
Validates no active appointments
Performs soft delete (archive)
Publishes service deleted event
Handles cleanup of related data
Safety Validations:
Cannot delete services with active bookings
Cannot delete services referenced in orders
Cannot delete services with pending payments
Validates business continuity
Cleanup Process:
Archives service data
Maintains historical references
Cleans up caches
Notifies dependent systems
Output: { deletedCount: number }
6. Update Service Banners Use Case
Purpose: Manages service banner images and media presentation.
Location: UpdateServiceBannersUseCase
Input Parameters:
ctx: TenantActorContext- Context with tenant and actor informationserviceId: string- ID of service to updatemedia: any- Media metadatafile: Express.Multer.File- Uploaded image file
Business Logic:
Validates actor permissions (
CREATE_SERVICE)Validates file format and size
Processes image upload
Updates service presentation
Optimizes images for different sizes
Updates service media references
File Processing:
Validates image formats (JPEG, PNG, WebP)
Enforces file size limits
Generates thumbnails
Optimizes for web delivery
Handles storage integration
Output: MediaDto (uploaded media information)
7. Delete Service Banner Use Case
Purpose: Removes specific banner images from service presentation.
Location: DeleteServiceBannerUseCase
Input Parameters:
ctx: TenantActorContext- Context with tenant and actor informationserviceId: string- ID of servicebannerId: string- ID of banner to delete
Business Logic:
Validates actor permissions (
CREATE_SERVICE)Validates banner exists for service
Removes banner from service presentation
Deletes media files from storage
Updates service presentation data
Storage Cleanup:
Removes files from storage
Cleans up thumbnails
Updates CDN references
Maintains data consistency
Output: { deletedCount: number }
8. Update Service Required Resources Use Case
Purpose: Manages resource requirements for service delivery.
Location: UpdateServiceRequiredResourcesUseCase
Input Parameters:
ctx: TenantActorContext- Context with tenant and actor informationserviceId: string- ID of servicerequiredResources: RequiredResourceDto[]- Resource requirements
Business Logic:
Validates actor permissions (
EDIT_SERVICE)Validates resource references exist
Validates resource quantities
Updates service resource requirements
Handles resource availability checking
Resource Validation:
Ensures resources exist in system
Validates quantity requirements
Checks resource availability
Validates business constraints
Output: void
Permission Requirements
All service management use cases require specific permissions validated through PermissionValidatorUseCase:
READ_SERVICE: Required for viewing services
CREATE_SERVICE: Required for creating services and managing media
EDIT_SERVICE: Required for updating services and resources
DELETE_SERVICE: Required for deleting services
Error Handling
Common Exceptions
ServiceNotFoundException: When service ID doesn't existServiceCreationException: When service creation validation failsServiceUpdationException: When service update validation failsServiceDeletionException: When service cannot be deletedMediaUploadException: When media upload failsResourceNotFoundException: When required resource doesn't exist
Error Response Pattern
All use cases follow consistent error handling:
Log errors with context and stack trace
Preserve original error for debugging
Throw domain-specific exceptions
Handle transaction rollback automatically
Provide meaningful error messages
Business Rules
Service Creation Rules
Language Requirements: At least one language version mandatory
Duration Configuration: Valid duration and pricing required
Presentation: Color format validation and media constraints
Scheduling: Schedule validation and conflict checking
Resource Requirements: Valid resource references
Service Update Rules
Data Integrity: Cannot remove all language/duration versions
Active Bookings: Cannot modify services with active appointments
Pricing Changes: Proper validation for price updates
Media Management: File format and size validation
Resource Updates: Availability and constraint checking
Service Deletion Rules
Dependency Checking: Cannot delete services with active references
Soft Delete: Services are archived, not physically removed
Data Preservation: Historical data maintained for reporting
Cleanup Process: Proper cleanup of related data
Media Management Rules
File Formats: Only JPEG, PNG, WebP allowed
File Size: Maximum 10MB per file
Image Processing: Automatic optimization and thumbnail generation
Storage Management: Efficient storage and CDN integration
Integration Points
Event Publishing
ServiceCreatedEvent: Published when service is created
ServiceUpdatedEvent: Published when service is updated
ServiceDeletedEvent: Published when service is deleted
MediaUploadedEvent: Published when media is uploaded
Cache Management
Automatic cache invalidation on mutations
Cache keys:
GET_SERVICE,GET_PAGED_SERVICES,GET_PUBLIC_SERVICESUses distributed caching for performance
TTL-based cache expiration
External Services
Storage Service: For media file management
Image Processing: For thumbnail generation
CDN Integration: For media delivery optimization
Search Service: For enhanced search capabilities
Performance Considerations
Query Optimization
Indexed searches for pagination
Efficient phrase search implementation
Optimized loading of related data
Proper query result caching
Media Processing
Asynchronous image processing
Multiple size generation
Efficient storage utilization
CDN integration for delivery
Caching Strategy
Multi-level caching approach
Cache warming for popular services
Intelligent cache invalidation
Performance monitoring
Testing Strategy
Unit Tests
Mock all external dependencies
Test business logic in isolation
Cover all error scenarios
Validate permission checks
Test validation rules
Integration Tests
Test with real database
Validate transaction behavior
Test event publishing
Cache integration testing
Media upload testing
End-to-End Tests
Full workflow testing
API endpoint validation
File upload and processing
Permission integration testing
Performance benchmarking
Monitoring and Observability
Metrics Collection
Use case execution times
Error rates and types
Cache hit ratios
Media processing metrics
Resource utilization
Logging Strategy
Structured logging with correlation IDs
Business event logging
Error tracking with context
Performance monitoring
Security audit logging
Health Checks
Database connectivity
Storage service availability
Cache system health
External service dependencies
Business rule validation
Future Enhancements
Planned Features
Advanced Search: Elasticsearch integration for complex queries
AI Recommendations: Machine learning for service suggestions
Dynamic Pricing: Time-based and demand-based pricing
Service Templates: Reusable service configuration templates
Bulk Operations: Mass service management capabilities
Technical Improvements
Event Sourcing: Complete audit trail with event streams
Microservice Split: Separate media and core service management
GraphQL API: Enhanced query capabilities
Real-time Updates: WebSocket integration for live updates
Advanced Analytics: Service performance and usage analytics
Security Considerations
Data Protection
PII handling in service descriptions
Secure media storage and access
Role-based access control
Audit logging for compliance
Input Validation
Comprehensive validation rules
SQL injection prevention
File upload security
Cross-site scripting protection
Business Logic Security
Permission validation at use case level
Resource access validation
Multi-tenant data isolation
Rate limiting and abuse prevention
Last updated
Was this helpful?