dt-common-device
Version:
A secure and robust device management library for IoT applications
110 lines (109 loc) • 3.54 kB
TypeScript
import { CreateIssueData, IssuesCategory, IssuePriority, EntityType } from "./issue.types";
/**
* IssueBuilder - A builder pattern implementation for constructing CreateIssueData objects
*
* This builder provides a fluent interface for creating issue data with proper validation
* and default values. It follows the Builder pattern which is a standard design pattern
* in TypeScript for constructing complex objects.
*
* Usage example:
* const issueData = new IssueBuilder()
* .setCategory(IssuesCategory.OPERATIONS)
* .setPropertyId("prop123")
* .setTitle("Device Maintenance Required")
* .setDescription("Device requires scheduled maintenance")
* .setEntityId("device456")
* .setEntityType(EntityType.DEVICE)
* .setPriority(IssuePriority.HIGH)
* .setAssignedTo("tech789")
* .setCreatedBy("user123")
* .setDueDate(new Date("2024-01-15"))
* .build();
*/
export declare class IssueBuilder {
private data;
/**
* Sets the issue category
*/
setCategory(category: IssuesCategory): IssueBuilder;
/**
* Sets the property ID
*/
setPropertyId(propertyId: string): IssueBuilder;
/**
* Sets the issue title
*/
setTitle(title: string): IssueBuilder;
/**
* Sets the issue description
*/
setDescription(description: string): IssueBuilder;
/**
* Sets the entity ID (optional)
*/
setEntityId(entityId?: string): IssueBuilder;
/**
* Sets the entity type
*/
setEntityType(entityType: EntityType): IssueBuilder;
/**
* Sets the issue priority (optional, defaults to MEDIUM)
*/
setPriority(priority?: IssuePriority): IssueBuilder;
/**
* Sets the user assigned to the issue (optional)
*/
setAssignedTo(assignedTo?: string): IssueBuilder;
/**
* Sets the user who created the issue (required)
*/
setCreatedBy(createdBy: string): IssueBuilder;
/**
* Sets the due date (optional)
*/
setDueDate(dueDate?: Date): IssueBuilder;
/**
* Validates that all required fields are present
*/
private validate;
/**
* Builds and returns the CreateIssueData object
* @throws Error if required fields are missing
*/
build(): CreateIssueData;
/**
* Resets the builder to its initial state
*/
reset(): IssueBuilder;
/**
* Creates a new builder instance with predefined values for common issue types
*/
static createReadinessIssue(): IssueBuilder;
static createOperationsIssue(): IssueBuilder;
static createSecurityIssue(): IssueBuilder;
static createEnergyIssue(): IssueBuilder;
/**
* Creates a device-specific issue builder
*/
static createDeviceIssue(deviceId: string, propertyId: string): IssueBuilder;
/**
* Creates a hub-specific issue builder
*/
static createHubIssue(hubId: string, propertyId: string): IssueBuilder;
/**
* Creates a user-specific issue builder
*/
static createUserIssue(userId: string, propertyId: string): IssueBuilder;
/**
* Creates a property-specific issue builder
*/
static createPropertyIssue(propertyId: string): IssueBuilder;
/**
* Creates a maintenance issue builder
*/
static createMaintenanceIssue(propertyId: string, entityId?: string, entityType?: EntityType): IssueBuilder;
/**
* Creates an urgent issue builder
*/
static createUrgentIssue(propertyId: string, entityId?: string, entityType?: EntityType): IssueBuilder;
}