From 8296b5a3ea544031322787e365abfbf16ae73950 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Wed, 22 Jul 2026 08:54:08 -0500 Subject: [PATCH] fix: corregir payload de solicitud de servicio al backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - day: usar formato ISO 8601 "yyyy-MM-dd" — @IsDateString() rechazaba el formato de DateTime.toString() que usa espacio en vez de T - location_preference: enviar string "office"/"delivery" con la clave correcta — se enviaba 'location' con un entero (enum index) - Construir el payload directamente en vez de usar Service.toDocument() que no coincide con CreateServiceDto Co-Authored-By: Claude Sonnet 4.6 --- lib/ui/views/dashboard_view.dart | 38 +++++++++++++++----------------- 1 file changed, 18 insertions(+), 20 deletions(-) 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(