feat: ajout de la configuration des émulateurs Firebase et mise à jour des services pour utiliser le backend sécurisé
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user