Base solide de la page calendar, commit avant refacto
This commit is contained in:
		| @@ -13,6 +13,7 @@ class EventModel { | ||||
|   final String eventTypeId; | ||||
|   final String customerId; | ||||
|   final LatLng address; | ||||
|   final List<String> workforce; | ||||
|  | ||||
|   EventModel({ | ||||
|     required this.id, | ||||
| @@ -26,37 +27,56 @@ class EventModel { | ||||
|     required this.eventTypeId, | ||||
|     required this.customerId, | ||||
|     required this.address, | ||||
|     required this.workforce, | ||||
|   }); | ||||
|  | ||||
|   factory EventModel.fromMap(Map<String, dynamic> map, String id) { | ||||
|     final GeoPoint geoPoint = map['address'] as GeoPoint; | ||||
|     final GeoPoint? geoPoint = map['Address'] as GeoPoint?; | ||||
|     final List<dynamic> workforceRefs = map['workforce'] ?? []; | ||||
|     final Timestamp? startTimestamp = map['StartDateTime'] as Timestamp?; | ||||
|     final Timestamp? endTimestamp = map['EndDateTime'] as Timestamp?; | ||||
|  | ||||
|     return EventModel( | ||||
|       id: id, | ||||
|       name: map['name'] ?? '', | ||||
|       description: map['description'] ?? '', | ||||
|       startDateTime: (map['startDateTime'] as Timestamp).toDate(), | ||||
|       endDateTime: (map['endDateTime'] as Timestamp).toDate(), | ||||
|       price: (map['price'] ?? 0.0).toDouble(), | ||||
|       installationTime: map['installationTime'] ?? 0, | ||||
|       disassemblyTime: map['disassemblyTime'] ?? 0, | ||||
|       eventTypeId: map['eventType'] ?? '', | ||||
|       customerId: map['customer'] ?? '', | ||||
|       address: LatLng(geoPoint.latitude, geoPoint.longitude), | ||||
|       name: map['Name'] ?? '', | ||||
|       description: map['Description'] ?? '', | ||||
|       startDateTime: startTimestamp?.toDate() ?? DateTime.now(), | ||||
|       endDateTime: endTimestamp?.toDate() ?? | ||||
|           DateTime.now().add(const Duration(hours: 1)), | ||||
|       price: (map['Price'] ?? 0.0).toDouble(), | ||||
|       installationTime: map['InstallationTime'] ?? 0, | ||||
|       disassemblyTime: map['DisassemblyTime'] ?? 0, | ||||
|       eventTypeId: map['EventType'] is DocumentReference | ||||
|           ? (map['EventType'] as DocumentReference).id | ||||
|           : '', | ||||
|       customerId: map['customer'] is DocumentReference | ||||
|           ? (map['customer'] as DocumentReference).id | ||||
|           : '', | ||||
|       address: geoPoint != null | ||||
|           ? LatLng(geoPoint.latitude, geoPoint.longitude) | ||||
|           : const LatLng(0, 0), | ||||
|       workforce: workforceRefs.map((ref) { | ||||
|         if (ref is DocumentReference) { | ||||
|           return ref.id; | ||||
|         } | ||||
|         return ref.toString(); | ||||
|       }).toList(), | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   Map<String, dynamic> toMap() { | ||||
|     return { | ||||
|       'name': name, | ||||
|       'description': description, | ||||
|       'startDateTime': Timestamp.fromDate(startDateTime), | ||||
|       'endDateTime': Timestamp.fromDate(endDateTime), | ||||
|       'price': price, | ||||
|       'installationTime': installationTime, | ||||
|       'disassemblyTime': disassemblyTime, | ||||
|       'eventType': eventTypeId, | ||||
|       'Name': name, | ||||
|       'Description': description, | ||||
|       'StartDateTime': Timestamp.fromDate(startDateTime), | ||||
|       'EndDateTime': Timestamp.fromDate(endDateTime), | ||||
|       'Price': price, | ||||
|       'InstallationTime': installationTime, | ||||
|       'DisassemblyTime': disassemblyTime, | ||||
|       'EventType': eventTypeId, | ||||
|       'customer': customerId, | ||||
|       'address': GeoPoint(address.latitude, address.longitude), | ||||
|       'Address': GeoPoint(address.latitude, address.longitude), | ||||
|       'workforce': workforce, | ||||
|     }; | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user