UNPKG

dt-common-device

Version:

A secure and robust device management library for IoT applications

138 lines (137 loc) 5.62 kB
import { AlertRepository } from "../repository/Alert.repository"; import { IAlertDocument } from "../models/Alert.model"; import { CreateAlertData, UpdateAlertData, AlertCategory, AlertSeverity, EntityType } from "../../../types/alert.types"; import { AlertBuilder } from "../entities/AlertBuilder"; 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, severity?: AlertSeverity, createdBy?: string): Promise<IAlertDocument>; /** * Create a hub-specific alert using AlertBuilder */ raiseHubAlert(hubId: string, propertyId: string, title: string, description: string, category?: AlertCategory, severity?: AlertSeverity, createdBy?: 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; 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, 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; }