feat: ajout de la configuration des émulateurs Firebase et mise à jour des services pour utiliser le backend sécurisé
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
|
||||
enum AlertType {
|
||||
lowStock, // Stock faible
|
||||
@@ -48,12 +48,20 @@ class AlertModel {
|
||||
});
|
||||
|
||||
factory AlertModel.fromMap(Map<String, dynamic> map, String id) {
|
||||
// Fonction helper pour convertir Timestamp ou String ISO en DateTime
|
||||
DateTime _parseDate(dynamic value) {
|
||||
if (value == null) return DateTime.now();
|
||||
if (value is Timestamp) return value.toDate();
|
||||
if (value is String) return DateTime.tryParse(value) ?? DateTime.now();
|
||||
return DateTime.now();
|
||||
}
|
||||
|
||||
return AlertModel(
|
||||
id: id,
|
||||
type: alertTypeFromString(map['type']),
|
||||
message: map['message'] ?? '',
|
||||
equipmentId: map['equipmentId'],
|
||||
createdAt: (map['createdAt'] as Timestamp?)?.toDate() ?? DateTime.now(),
|
||||
createdAt: _parseDate(map['createdAt']),
|
||||
isRead: map['isRead'] ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -242,6 +242,14 @@ class ContainerModel {
|
||||
|
||||
/// Factory depuis Firestore
|
||||
factory ContainerModel.fromMap(Map<String, dynamic> map, String id) {
|
||||
// Fonction helper pour convertir Timestamp ou String ISO en DateTime
|
||||
DateTime? _parseDate(dynamic value) {
|
||||
if (value == null) return null;
|
||||
if (value is Timestamp) return value.toDate();
|
||||
if (value is String) return DateTime.tryParse(value);
|
||||
return null;
|
||||
}
|
||||
|
||||
final List<dynamic> equipmentIdsRaw = map['equipmentIds'] ?? [];
|
||||
final List<String> equipmentIds = equipmentIdsRaw.map((e) => e.toString()).toList();
|
||||
|
||||
@@ -262,8 +270,8 @@ class ContainerModel {
|
||||
equipmentIds: equipmentIds,
|
||||
eventId: map['eventId'],
|
||||
notes: map['notes'],
|
||||
createdAt: (map['createdAt'] as Timestamp?)?.toDate() ?? DateTime.now(),
|
||||
updatedAt: (map['updatedAt'] as Timestamp?)?.toDate() ?? DateTime.now(),
|
||||
createdAt: _parseDate(map['createdAt']) ?? DateTime.now(),
|
||||
updatedAt: _parseDate(map['updatedAt']) ?? DateTime.now(),
|
||||
history: history,
|
||||
);
|
||||
}
|
||||
@@ -342,8 +350,16 @@ class ContainerHistoryEntry {
|
||||
});
|
||||
|
||||
factory ContainerHistoryEntry.fromMap(Map<String, dynamic> map) {
|
||||
// Helper pour parser la date
|
||||
DateTime _parseDate(dynamic value) {
|
||||
if (value == null) return DateTime.now();
|
||||
if (value is Timestamp) return value.toDate();
|
||||
if (value is String) return DateTime.tryParse(value) ?? DateTime.now();
|
||||
return DateTime.now();
|
||||
}
|
||||
|
||||
return ContainerHistoryEntry(
|
||||
timestamp: (map['timestamp'] as Timestamp?)?.toDate() ?? DateTime.now(),
|
||||
timestamp: _parseDate(map['timestamp']),
|
||||
action: map['action'] ?? '',
|
||||
equipmentId: map['equipmentId'],
|
||||
previousValue: map['previousValue'],
|
||||
|
||||
@@ -359,6 +359,14 @@ class EquipmentModel {
|
||||
});
|
||||
|
||||
factory EquipmentModel.fromMap(Map<String, dynamic> map, String id) {
|
||||
// Fonction helper pour convertir Timestamp ou String ISO en DateTime
|
||||
DateTime? _parseDate(dynamic value) {
|
||||
if (value == null) return null;
|
||||
if (value is Timestamp) return value.toDate();
|
||||
if (value is String) return DateTime.tryParse(value);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Gestion des listes
|
||||
final List<dynamic> parentBoxIdsRaw = map['parentBoxIds'] ?? [];
|
||||
final List<String> parentBoxIds = parentBoxIdsRaw.map((e) => e.toString()).toList();
|
||||
@@ -383,13 +391,13 @@ class EquipmentModel {
|
||||
length: map['length']?.toDouble(),
|
||||
width: map['width']?.toDouble(),
|
||||
height: map['height']?.toDouble(),
|
||||
purchaseDate: (map['purchaseDate'] as Timestamp?)?.toDate(),
|
||||
nextMaintenanceDate: (map['nextMaintenanceDate'] as Timestamp?)?.toDate(),
|
||||
purchaseDate: _parseDate(map['purchaseDate']),
|
||||
nextMaintenanceDate: _parseDate(map['nextMaintenanceDate']),
|
||||
maintenanceIds: maintenanceIds,
|
||||
imageUrl: map['imageUrl'],
|
||||
notes: map['notes'],
|
||||
createdAt: (map['createdAt'] as Timestamp?)?.toDate() ?? DateTime.now(),
|
||||
updatedAt: (map['updatedAt'] as Timestamp?)?.toDate() ?? DateTime.now(),
|
||||
createdAt: _parseDate(map['createdAt']) ?? DateTime.now(),
|
||||
updatedAt: _parseDate(map['updatedAt']) ?? DateTime.now(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -300,6 +300,14 @@ class EventModel {
|
||||
|
||||
factory EventModel.fromMap(Map<String, dynamic> map, String id) {
|
||||
try {
|
||||
// Fonction helper pour convertir Timestamp ou String ISO en DateTime
|
||||
DateTime _parseDate(dynamic value, DateTime defaultValue) {
|
||||
if (value == null) return defaultValue;
|
||||
if (value is Timestamp) return value.toDate();
|
||||
if (value is String) return DateTime.tryParse(value) ?? defaultValue;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
// Gestion sécurisée des références workforce
|
||||
final List<dynamic> workforceRefs = map['workforce'] ?? [];
|
||||
final List<DocumentReference> safeWorkforce = [];
|
||||
@@ -312,13 +320,9 @@ class EventModel {
|
||||
}
|
||||
}
|
||||
|
||||
// Gestion sécurisée des timestamps
|
||||
final Timestamp? startTimestamp = map['StartDateTime'] as Timestamp?;
|
||||
final Timestamp? endTimestamp = map['EndDateTime'] as Timestamp?;
|
||||
|
||||
final DateTime startDate = startTimestamp?.toDate() ?? DateTime.now();
|
||||
final DateTime endDate = endTimestamp?.toDate() ??
|
||||
startDate.add(const Duration(hours: 1));
|
||||
// Gestion sécurisée des timestamps avec support ISO string
|
||||
final DateTime startDate = _parseDate(map['StartDateTime'], DateTime.now());
|
||||
final DateTime endDate = _parseDate(map['EndDateTime'], startDate.add(const Duration(hours: 1)));
|
||||
|
||||
// Gestion sécurisée des documents
|
||||
final docsRaw = map['documents'] ?? [];
|
||||
@@ -365,7 +369,13 @@ class EventModel {
|
||||
eventTypeRef = map['EventType'] as DocumentReference;
|
||||
eventTypeId = eventTypeRef.id;
|
||||
} else if (map['EventType'] is String) {
|
||||
eventTypeId = map['EventType'] as String;
|
||||
final eventTypeString = map['EventType'] as String;
|
||||
// Si c'est un path (ex: "eventTypes/Mariage"), extraire juste l'ID
|
||||
if (eventTypeString.contains('/')) {
|
||||
eventTypeId = eventTypeString.split('/').last;
|
||||
} else {
|
||||
eventTypeId = eventTypeString;
|
||||
}
|
||||
}
|
||||
|
||||
// Gestion sécurisée du customer
|
||||
@@ -373,7 +383,13 @@ class EventModel {
|
||||
if (map['customer'] is DocumentReference) {
|
||||
customerId = (map['customer'] as DocumentReference).id;
|
||||
} else if (map['customer'] is String) {
|
||||
customerId = map['customer'] as String;
|
||||
final customerString = map['customer'] as String;
|
||||
// Si c'est un path (ex: "clients/abc123"), extraire juste l'ID
|
||||
if (customerString.contains('/')) {
|
||||
customerId = customerString.split('/').last;
|
||||
} else {
|
||||
customerId = customerString;
|
||||
}
|
||||
}
|
||||
|
||||
// Gestion des équipements assignés
|
||||
@@ -495,4 +511,64 @@ class EventModel {
|
||||
'returnStatus': returnStatus != null ? returnStatusToString(returnStatus!) : null,
|
||||
};
|
||||
}
|
||||
|
||||
EventModel copyWith({
|
||||
String? id,
|
||||
String? name,
|
||||
String? description,
|
||||
DateTime? startDateTime,
|
||||
DateTime? endDateTime,
|
||||
double? basePrice,
|
||||
int? installationTime,
|
||||
int? disassemblyTime,
|
||||
String? eventTypeId,
|
||||
DocumentReference? eventTypeRef,
|
||||
String? customerId,
|
||||
String? address,
|
||||
double? latitude,
|
||||
double? longitude,
|
||||
List<DocumentReference>? workforce,
|
||||
List<Map<String, String>>? documents,
|
||||
List<Map<String, dynamic>>? options,
|
||||
EventStatus? status,
|
||||
int? jauge,
|
||||
String? contactEmail,
|
||||
String? contactPhone,
|
||||
List<EventEquipment>? assignedEquipment,
|
||||
List<String>? assignedContainers,
|
||||
PreparationStatus? preparationStatus,
|
||||
LoadingStatus? loadingStatus,
|
||||
UnloadingStatus? unloadingStatus,
|
||||
ReturnStatus? returnStatus,
|
||||
}) {
|
||||
return EventModel(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
description: description ?? this.description,
|
||||
startDateTime: startDateTime ?? this.startDateTime,
|
||||
endDateTime: endDateTime ?? this.endDateTime,
|
||||
basePrice: basePrice ?? this.basePrice,
|
||||
installationTime: installationTime ?? this.installationTime,
|
||||
disassemblyTime: disassemblyTime ?? this.disassemblyTime,
|
||||
eventTypeId: eventTypeId ?? this.eventTypeId,
|
||||
eventTypeRef: eventTypeRef ?? this.eventTypeRef,
|
||||
customerId: customerId ?? this.customerId,
|
||||
address: address ?? this.address,
|
||||
latitude: latitude ?? this.latitude,
|
||||
longitude: longitude ?? this.longitude,
|
||||
workforce: workforce ?? this.workforce,
|
||||
documents: documents ?? this.documents,
|
||||
options: options ?? this.options,
|
||||
status: status ?? this.status,
|
||||
jauge: jauge ?? this.jauge,
|
||||
contactEmail: contactEmail ?? this.contactEmail,
|
||||
contactPhone: contactPhone ?? this.contactPhone,
|
||||
assignedEquipment: assignedEquipment ?? this.assignedEquipment,
|
||||
assignedContainers: assignedContainers ?? this.assignedContainers,
|
||||
preparationStatus: preparationStatus ?? this.preparationStatus,
|
||||
loadingStatus: loadingStatus ?? this.loadingStatus,
|
||||
unloadingStatus: unloadingStatus ?? this.unloadingStatus,
|
||||
returnStatus: returnStatus ?? this.returnStatus,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,14 @@ class MaintenanceModel {
|
||||
});
|
||||
|
||||
factory MaintenanceModel.fromMap(Map<String, dynamic> map, String id) {
|
||||
// Fonction helper pour convertir Timestamp ou String ISO en DateTime
|
||||
DateTime? _parseDate(dynamic value) {
|
||||
if (value == null) return null;
|
||||
if (value is Timestamp) return value.toDate();
|
||||
if (value is String) return DateTime.tryParse(value);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Gestion de la liste des équipements
|
||||
final List<dynamic> equipmentIdsRaw = map['equipmentIds'] ?? [];
|
||||
final List<String> equipmentIds = equipmentIdsRaw.map((e) => e.toString()).toList();
|
||||
@@ -68,15 +76,15 @@ class MaintenanceModel {
|
||||
id: id,
|
||||
equipmentIds: equipmentIds,
|
||||
type: maintenanceTypeFromString(map['type']),
|
||||
scheduledDate: (map['scheduledDate'] as Timestamp?)?.toDate() ?? DateTime.now(),
|
||||
completedDate: (map['completedDate'] as Timestamp?)?.toDate(),
|
||||
scheduledDate: _parseDate(map['scheduledDate']) ?? DateTime.now(),
|
||||
completedDate: _parseDate(map['completedDate']),
|
||||
name: map['name'] ?? '',
|
||||
description: map['description'] ?? '',
|
||||
performedBy: map['performedBy'],
|
||||
cost: map['cost']?.toDouble(),
|
||||
notes: map['notes'],
|
||||
createdAt: (map['createdAt'] as Timestamp?)?.toDate() ?? DateTime.now(),
|
||||
updatedAt: (map['updatedAt'] as Timestamp?)?.toDate() ?? DateTime.now(),
|
||||
createdAt: _parseDate(map['createdAt']) ?? DateTime.now(),
|
||||
updatedAt: _parseDate(map['updatedAt']) ?? DateTime.now(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user