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:
co-authored by
Claude Sonnet 4.6
parent
462d47d182
commit
8296b5a3ea
@@ -370,26 +370,24 @@ class _DashboardViewState extends State<DashboardView> {
|
||||
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user