fix: runtime fixes for service model and paginated responses
- Service.fromJson: string status/location enums, ISO8601 time parsing, additional_address field name
- _loadServices: unwrap {data:[...]} paginated response; extract embedded user from response instead of extra API calls
- calendar_services_provider: same response unwrap; fallback user when not embedded
- Add ProState import where needed
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
0ecca498ad
commit
a4a6099722
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:prosapp_web_app/models/pro_state.dart';
|
||||
import 'package:prosapp_web_app/models/service.dart';
|
||||
import 'package:prosapp_web_app/models/servicio_profesional.dart';
|
||||
import 'package:prosapp_web_app/models/usuario.dart';
|
||||
@@ -20,7 +21,10 @@ class CalendarServicesProvider extends ChangeNotifier {
|
||||
getServicesForProfessional(String userId) async {
|
||||
try {
|
||||
isLoading = true;
|
||||
final data = await _api.get('/services/professional/calendar') as List;
|
||||
final res = await _api.get('/services/professional/calendar');
|
||||
final data = (res is Map ? res['data'] : res) as List;
|
||||
|
||||
// Fetch users for calendar entries (calendar endpoint returns flat list without embedded users)
|
||||
final servicios = data.map((e) {
|
||||
final m = e as Map<String, dynamic>;
|
||||
return Service.fromJson(m, m['id'] as String);
|
||||
@@ -34,7 +38,11 @@ class CalendarServicesProvider extends ChangeNotifier {
|
||||
final usersMap = {for (var u in users) u.id: u};
|
||||
|
||||
services = servicios
|
||||
.map((s) => ServicioProfesional(user: usersMap[s.userId]!, service: s))
|
||||
.map((s) => ServicioProfesional(
|
||||
user: usersMap[s.userId] ?? Usuario(id: s.userId, email: null, phone: null, name: '?',
|
||||
nickname: null, city: null, picture: null, birthday: null, gender: null,
|
||||
proState: ProState.inactive, token: null),
|
||||
service: s))
|
||||
.toList()
|
||||
..sort((a, b) {
|
||||
final dateA = DateTime.parse(a.service.day);
|
||||
|
||||
Reference in New Issue
Block a user