diff --git a/lib/ui/views/dashboard_view.dart b/lib/ui/views/dashboard_view.dart index 033a21f..128f747 100644 --- a/lib/ui/views/dashboard_view.dart +++ b/lib/ui/views/dashboard_view.dart @@ -370,26 +370,24 @@ class _DashboardViewState extends State { setState(() => _requesting = true); try { - final service = Service( - id: null, - professionalId: _professional!.user.id, - professionalScored: false, - userId: user!.id, - userScored: false, - address: isOfficeOnly ? _professional!.professionalInfo.address : _currentAddress, - aditionalAddress: '', - latitude: isOfficeOnly ? _professional!.professionalInfo.latitude : _mapCenter.latitude, - longitude: isOfficeOnly ? _professional!.professionalInfo.longitude : _mapCenter.longitude, - day: _selectedDay.toString(), - createdAt: DateTime.now().toIso8601String(), - description: '', - range1Hour1: _selectedHour!, - range1Hour2: _selectedHour!.add(minute: _professional!.professionalInfo.slotDurationMinutes), - rate: '', - status: ServiceStatus.pending, - location: serviceLocation, - ); - await ApiService.instance.post('/services', service.toDocument()); + final slot = _selectedHour!; + final endSlot = slot.add(minute: _professional!.professionalInfo.slotDurationMinutes); + String pad(int n) => n.toString().padLeft(2, '0'); + + // Build payload matching CreateServiceDto exactly + final payload = { + 'professional_id': _professional!.user.id, + // @IsDateString() expects ISO 8601 date — "yyyy-MM-dd" + 'day': '${_selectedDay!.year}-${pad(_selectedDay!.month)}-${pad(_selectedDay!.day)}', + 'range1_hour1': '${pad(slot.hour)}:${pad(slot.minute)}', + 'range1_hour2': '${pad(endSlot.hour)}:${pad(endSlot.minute)}', + 'address': isOfficeOnly ? _professional!.professionalInfo.address : _currentAddress, + 'latitude': isOfficeOnly ? _professional!.professionalInfo.latitude : _mapCenter.latitude, + 'longitude': isOfficeOnly ? _professional!.professionalInfo.longitude : _mapCenter.longitude, + // @IsEnum(['office','delivery']) expects the string value, not an integer + 'location_preference': isOfficeOnly ? 'office' : 'delivery', + }; + await ApiService.instance.post('/services', payload); NotificationsService.showSnackbar('Servicio solicitado exitosamente'); if (_professional!.user.token != null) { LocalNotifications.sendPushNotification(