fix: corregir payload de solicitud de servicio al backend

- 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 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-22 08:54:08 -05:00
co-authored by Claude Sonnet 4.6
parent 462d47d182
commit 8296b5a3ea
+18 -20
View File
@@ -370,26 +370,24 @@ class _DashboardViewState extends State<DashboardView> {
setState(() => _requesting = true); setState(() => _requesting = true);
try { try {
final service = Service( final slot = _selectedHour!;
id: null, final endSlot = slot.add(minute: _professional!.professionalInfo.slotDurationMinutes);
professionalId: _professional!.user.id, String pad(int n) => n.toString().padLeft(2, '0');
professionalScored: false,
userId: user!.id, // Build payload matching CreateServiceDto exactly
userScored: false, final payload = {
address: isOfficeOnly ? _professional!.professionalInfo.address : _currentAddress, 'professional_id': _professional!.user.id,
aditionalAddress: '', // @IsDateString() expects ISO 8601 date — "yyyy-MM-dd"
latitude: isOfficeOnly ? _professional!.professionalInfo.latitude : _mapCenter.latitude, 'day': '${_selectedDay!.year}-${pad(_selectedDay!.month)}-${pad(_selectedDay!.day)}',
longitude: isOfficeOnly ? _professional!.professionalInfo.longitude : _mapCenter.longitude, 'range1_hour1': '${pad(slot.hour)}:${pad(slot.minute)}',
day: _selectedDay.toString(), 'range1_hour2': '${pad(endSlot.hour)}:${pad(endSlot.minute)}',
createdAt: DateTime.now().toIso8601String(), 'address': isOfficeOnly ? _professional!.professionalInfo.address : _currentAddress,
description: '', 'latitude': isOfficeOnly ? _professional!.professionalInfo.latitude : _mapCenter.latitude,
range1Hour1: _selectedHour!, 'longitude': isOfficeOnly ? _professional!.professionalInfo.longitude : _mapCenter.longitude,
range1Hour2: _selectedHour!.add(minute: _professional!.professionalInfo.slotDurationMinutes), // @IsEnum(['office','delivery']) expects the string value, not an integer
rate: '', 'location_preference': isOfficeOnly ? 'office' : 'delivery',
status: ServiceStatus.pending, };
location: serviceLocation, await ApiService.instance.post('/services', payload);
);
await ApiService.instance.post('/services', service.toDocument());
NotificationsService.showSnackbar('Servicio solicitado exitosamente'); NotificationsService.showSnackbar('Servicio solicitado exitosamente');
if (_professional!.user.token != null) { if (_professional!.user.token != null) {
LocalNotifications.sendPushNotification( LocalNotifications.sendPushNotification(