dt-common-device
Version:
A secure and robust device management library for IoT applications
156 lines (155 loc) • 6.57 kB
TypeScript
import { AlertRepository } from "./Alert.repository";
import { IAlertDocument } from "./Alert.model";
import { CreateAlertData, UpdateAlertData, AlertCategory, AlertSeverity, EntityType } from "./alert.types";
import { Source } from "../constants/Service";
import { AlertBuilder } from "./AlertBuilder";
import { IDevice } from "../device/local/interfaces";
export declare class AlertService {
private readonly alertRepository;
constructor(alertRepository: AlertRepository);
/**
* Create a readiness alert using AlertBuilder
*/
raiseReadinessAlert(propertyId: string, title: string, description: string, entityId?: string, entityType?: EntityType, createdBy?: string): Promise<IAlertDocument>;
/**
* Create an operations alert using AlertBuilder
*/
raiseOperationsAlert(propertyId: string, title: string, description: string, entityId?: string, entityType?: EntityType, createdBy?: string): Promise<IAlertDocument>;
/**
* Create a security alert using AlertBuilder
*/
raiseSecurityAlert(propertyId: string, title: string, description: string, entityId?: string, entityType?: EntityType, createdBy?: string): Promise<IAlertDocument>;
/**
* Create an energy alert using AlertBuilder
*/
raiseEnergyAlert(propertyId: string, title: string, description: string, entityId?: string, entityType?: EntityType, createdBy?: string): Promise<IAlertDocument>;
/**
* Create a device-specific alert using AlertBuilder
*/
raiseDeviceAlert(deviceId: string, propertyId: string, title: string, description: string, category?: AlertCategory | AlertCategory[], severity?: AlertSeverity, source?: Source): Promise<IAlertDocument>;
/**
* Create a hub-specific alert using AlertBuilder
*/
raiseHubAlert(hubId: string, propertyId: string, title: string, description: string, category?: AlertCategory | AlertCategory[], severity?: AlertSeverity, createdBy?: string): Promise<IAlertDocument>;
/**
* Raise alert for device going offline (OPERATIONAL only)
*/
raiseDeviceOfflineAlert(device: IDevice, source: Source, reason?: string): Promise<IAlertDocument>;
/**
* Raise alert for device coming online (OPERATIONAL only)
*/
raiseDeviceOnlineAlert(device: IDevice, source: Source, reason?: string): Promise<IAlertDocument>;
/**
* Raise alert for device battery level below threshold (READINESS + OPERATIONAL + ENERGY)
*/
raiseDeviceBatteryAlert(device: IDevice, batteryLevel: number, threshold: number, source: Source): Promise<IAlertDocument>;
/**
* Raise alert for device issue (jammed or malfunctioned) (READINESS + OPERATIONAL)
*/
raiseDeviceIssueAlert(device: IDevice, issueType: string, source: Source, reason?: string): Promise<IAlertDocument>;
/**
* Create a new alert with business logic validation
* Accepts either a CreateAlertData object or an AlertBuilder instance
*/
createAlert(alertData: CreateAlertData | AlertBuilder): Promise<IAlertDocument>;
/**
* Get alert by ID with business logic
*/
getAlertById(id: string, includeDeleted?: boolean): Promise<IAlertDocument | null>;
/**
* Get all alerts with business logic filtering
*/
getAlerts(filters?: {
propertyId?: string;
category?: AlertCategory | AlertCategory[];
severity?: AlertSeverity;
entityType?: EntityType;
entityId?: string;
isActive?: boolean;
isRead?: boolean;
includeDeleted?: boolean;
limit?: number;
skip?: number;
}): Promise<IAlertDocument[]>;
/**
* Update an alert with business logic validation
*/
updateAlert(id: string, updateData: UpdateAlertData): Promise<IAlertDocument | null>;
/**
* Soft delete an alert with business logic
*/
deleteAlert(id: string, deletedBy: string): Promise<boolean>;
/**
* Mark alert as read with business logic
*/
markAsRead(id: string, updatedBy: string): Promise<IAlertDocument | null>;
/**
* Mark alert as unread with business logic
*/
markAsUnread(id: string, updatedBy: string): Promise<IAlertDocument | null>;
/**
* Activate an alert with business logic
*/
activateAlert(id: string, updatedBy: string): Promise<IAlertDocument | null>;
/**
* Deactivate an alert with business logic
*/
deactivateAlert(id: string, updatedBy: string): Promise<IAlertDocument | null>;
/**
* Snooze an alert with business logic
*/
snoozeAlert(id: string, until: Date, updatedBy: string): Promise<IAlertDocument | null>;
/**
* Unsnooze an alert with business logic
*/
unsnoozeAlert(id: string, updatedBy: string): Promise<IAlertDocument | null>;
/**
* Get alerts by property with business logic
*/
getAlertsByProperty(propertyId: string, includeDeleted?: boolean): Promise<IAlertDocument[]>;
/**
* Get alerts by entity with business logic
*/
getAlertsByEntity(entityId: string, entityType: EntityType, includeDeleted?: boolean): Promise<IAlertDocument[]>;
/**
* Get alerts by category with business logic
*/
getAlertsByCategory(category: AlertCategory | AlertCategory[], includeDeleted?: boolean): Promise<IAlertDocument[]>;
/**
* Get alerts by severity with business logic
*/
getAlertsBySeverity(severity: AlertSeverity, includeDeleted?: boolean): Promise<IAlertDocument[]>;
/**
* Get active alerts with business logic
*/
getActiveAlerts(includeDeleted?: boolean): Promise<IAlertDocument[]>;
/**
* Get unread alerts with business logic
*/
getUnreadAlerts(includeDeleted?: boolean): Promise<IAlertDocument[]>;
/**
* Get snoozed alerts with business logic
*/
getSnoozedAlerts(includeDeleted?: boolean): Promise<IAlertDocument[]>;
/**
* Get expired snooze alerts with business logic
*/
getExpiredSnoozeAlerts(includeDeleted?: boolean): Promise<IAlertDocument[]>;
/**
* Get alert statistics with business logic
*/
getAlertStatistics(propertyId?: string): Promise<{
total: number;
active: number;
unread: number;
snoozed: number;
bySeverity: Record<AlertSeverity, number>;
byCategory: Record<AlertCategory, number>;
}>;
private validateAlertData;
private validateFilters;
private validateUpdateData;
private validateSnoozeDate;
private determineDefaultSeverity;
private applyBusinessRules;
}