From d0e61ead97009c56476c332f16744821fa1411e5 Mon Sep 17 00:00:00 2001 From: dahoud <41957584+DahoudG@users.noreply.github.com> Date: Sat, 28 Mar 2026 14:25:59 +0000 Subject: [PATCH] Refactoring - Version stable --- .../domain/entities/financial_audit_log.dart | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/features/finance_workflow/domain/entities/financial_audit_log.dart b/lib/features/finance_workflow/domain/entities/financial_audit_log.dart index be1b9b4..211b4de 100644 --- a/lib/features/finance_workflow/domain/entities/financial_audit_log.dart +++ b/lib/features/finance_workflow/domain/entities/financial_audit_log.dart @@ -116,6 +116,46 @@ class FinancialAuditLog extends Equatable { this.metadata, }); + factory FinancialAuditLog.fromJson(Map json) { + return FinancialAuditLog( + id: json['id']?.toString() ?? '', + operation: AuditOperation.values.firstWhere( + (e) => e.name == json['operation'], + orElse: () => AuditOperation.read, + ), + entityType: AuditEntityType.values.firstWhere( + (e) => e.name == json['entityType'], + orElse: () => AuditEntityType.other, + ), + entityId: json['entityId']?.toString() ?? '', + userId: json['userId']?.toString() ?? '', + userName: json['userName']?.toString() ?? '', + userRole: json['userRole']?.toString() ?? '', + organizationId: json['organizationId']?.toString(), + severity: AuditSeverity.values.firstWhere( + (e) => e.name == json['severity'], + orElse: () => AuditSeverity.info, + ), + description: json['description']?.toString() ?? '', + dataBefore: json['dataBefore'] != null + ? Map.from(json['dataBefore'] as Map) + : null, + dataAfter: json['dataAfter'] != null + ? Map.from(json['dataAfter'] as Map) + : null, + amountBefore: (json['amountBefore'] as num?)?.toDouble(), + amountAfter: (json['amountAfter'] as num?)?.toDouble(), + ipAddress: json['ipAddress']?.toString(), + userAgent: json['userAgent']?.toString(), + timestamp: json['timestamp'] != null + ? DateTime.parse(json['timestamp'].toString()) + : DateTime.now(), + metadata: json['metadata'] != null + ? Map.from(json['metadata'] as Map) + : null, + ); + } + /// Vérifie si c'est une opération de modification de montant bool get isAmountChanged => amountBefore != null &&