fix: align Flutter endpoints and model parsing with actual NestJS backend

- Auth: phone login → POST /auth/phone (direct, no OTP); link phone → POST /auth/verify-phone; add email → POST /auth/link-email
- Services: replace query-param paths with dedicated role endpoints (/services/me, /services/professional/requests, /services/professional, etc.)
- Services: PATCH /services/:id → PATCH /services/:id/status
- Calendar: → GET /services/professional/calendar
- Professionals: /users/professionals → /professionals (handles {data:[...]} response)
- Professional info: /professional-info/:id → /professionals/:id; PATCH → /professionals/me
- Comments: /comments?... → /comments/user/:id and /comments/professional/:id
- Chat: /chats → /chat; start chat → POST /chat/start/:professionalId; poll GET /chat/:chatId/messages; send → POST /chat/:chatId/message
- Cities: /cities → GET /locations/countries (parse nested countries→regions→cities)
- Profesional.fromDocument: null-safe fields; convert schedules array→Schedules, specializations array→name/picture lists, payment_methods object/array
- Usuario.fromDocument: null-safe professional_state and id
- UsuarioProfesional.fromDocument: handle backend format (users nested, professional at top level)
- ScheduleEntity.parseTime: handle ISO8601 time strings from backend
- MessageEntity.fromDocument: accept sender_id (backend) or owner_id (legacy)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-18 16:07:44 -05:00
co-authored by Claude Sonnet 4.6
parent 60216fd0e3
commit 0ecca498ad
17 changed files with 183 additions and 101 deletions
+7 -23
View File
@@ -57,20 +57,12 @@ class AuthProvider extends ChangeNotifier {
}
Future<void> verifyPhoneNumber(String phoneNumber) async {
try {
await _api.post('/auth/phone/send', {'phone': phoneNumber});
notifyListeners();
} catch (e) {
NotificationsService.showSnackBarError('Error al enviar OTP');
}
// ponytail: backend does direct login by phone, no OTP step
}
Future<void> signInWithOTP(String phoneNumber, String smsCode) async {
try {
final data = await _api.post('/auth/phone/verify', {
'phone': phoneNumber,
'code': smsCode,
});
final data = await _api.post('/auth/phone', {'phone': phoneNumber});
await _api.saveToken(data['token'] as String);
user = Usuario.fromDocument(data['user'] as Map<String, dynamic>);
authStatus = AuthStatus.authenticated;
@@ -79,38 +71,30 @@ class AuthProvider extends ChangeNotifier {
} catch (e) {
authStatus = AuthStatus.notAuthenticated;
notifyListeners();
NotificationsService.showSnackBarError('Error en la verificación OTP');
NotificationsService.showSnackBarError('Error al iniciar sesión con teléfono');
}
}
Future<void> verifyPhoneNumberForLink(String phoneNumber) async {
try {
await _api.post('/auth/phone/link/send', {'phone': phoneNumber});
notifyListeners();
} catch (e) {
NotificationsService.showSnackBarError('Error al enviar OTP');
}
// ponytail: no OTP step, linkPhoneWithOTP does the actual call
}
Future<void> linkPhoneWithOTP(String phoneNumber, String smsCode) async {
try {
await _api.post('/auth/phone/link/verify', {
'phone': phoneNumber,
'code': smsCode,
});
await _api.post('/auth/verify-phone', {'phone': phoneNumber});
user = await _fetchMe();
NotificationsService.showSnackbar('Número vinculado exitosamente');
authStatus = AuthStatus.authenticated;
notifyListeners();
NavigationService.replaceTo(Flurorouter.profileRoute);
} catch (e) {
NotificationsService.showSnackBarError('Error en la verificación OTP');
NotificationsService.showSnackBarError('Error al vincular teléfono');
}
}
Future<void> addEmailAndPassword(String email, String password) async {
try {
await _api.patch('/users/me', {'email': email, 'password': password});
await _api.post('/auth/link-email', {'email': email, 'password': password});
user = await _fetchMe();
notifyListeners();
NotificationsService.showSnackbar('Email y contraseña añadidos exitosamente');
@@ -20,7 +20,7 @@ class CalendarServicesProvider extends ChangeNotifier {
getServicesForProfessional(String userId) async {
try {
isLoading = true;
final data = await _api.get('/services?professional_id=$userId&status=1,3') as List;
final data = await _api.get('/services/professional/calendar') as List;
final servicios = data.map((e) {
final m = e as Map<String, dynamic>;
return Service.fromJson(m, m['id'] as String);
+2 -2
View File
@@ -10,8 +10,8 @@ class ChatProvider with ChangeNotifier {
ChatEntity? _currentChat;
ChatEntity? get currentChat => _currentChat;
Stream<ChatEntity?> getChat(String chatId) {
return _firebaseChatRepository.getChatById(chatId).map((chat) {
Stream<ChatEntity?> getChat(String chatId, String professionalId) {
return _firebaseChatRepository.getChatById(chatId, professionalId).map((chat) {
_currentChat = chat;
notifyListeners();
return chat;
+20 -11
View File
@@ -20,17 +20,26 @@ class CitiesProvider extends ChangeNotifier {
getCities() async {
try {
final data = await _api.get('/cities') as List;
cities = data.map((e) {
final m = e as Map<String, dynamic>;
return City(
cityName: m['name'] as String,
coordsOfCity: m['coords'] as String? ?? '',
stateOfCity: m['state'] as String? ?? '',
countryOfCity: m['country'] as String? ?? 'Colombia',
);
}).toList();
cities.sort((a, b) => a.cityName.compareTo(b.cityName));
// GET /locations/countries returns nested {regions: [{cities: [...]}]}
final countries = await _api.get('/locations/countries') as List;
final result = <City>[];
for (final country in countries) {
final countryName = country['name'] as String? ?? 'Colombia';
for (final region in (country['regions'] as List? ?? [])) {
final regionName = region['name'] as String? ?? '';
for (final c in (region['cities'] as List? ?? [])) {
final lat = (c['latitude'] as num?)?.toDouble() ?? 0.0;
final lng = (c['longitude'] as num?)?.toDouble() ?? 0.0;
result.add(City(
cityName: c['name'] as String,
coordsOfCity: lat != 0.0 ? '$lat,$lng' : '',
stateOfCity: regionName,
countryOfCity: countryName,
));
}
}
}
cities = result..sort((a, b) => a.cityName.compareTo(b.cityName));
} catch (e) {
print('Error obteniendo ciudades: $e');
} finally {
@@ -17,7 +17,7 @@ class ProfessionalDetailProvider extends ChangeNotifier {
final userData = await _api.get('/users/$uid');
final user = Usuario.fromDocument(userData as Map<String, dynamic>);
final proData = await _api.get('/professional-info/$uid');
final proData = await _api.get('/professionals/$uid');
final professionalInfo = Profesional.fromDocument(proData as Map<String, dynamic>);
final repData = await _api.get('/comments/reputation/$uid');
@@ -64,20 +64,20 @@ class ProfessionalFormProvider with ChangeNotifier {
Future<bool> updateProfesionalInfo(String userId) async {
if (!_validForm()) return false;
await _api.patch('/professional-info/$userId', profesional!.toDocument());
await _api.patch('/professionals/me', profesional!.toDocument());
NotificationsService.showSnackbar('Información actualizada');
return true;
}
Future<bool> updateProfesionalProfileInfo(String userId) async {
if (!_validProfileForm()) return false;
await _api.patch('/professional-info/$userId', profesional!.toDocument());
await _api.patch('/professionals/me', profesional!.toDocument());
NotificationsService.showSnackbar('Información actualizada');
return true;
}
Future<bool> updateProfesionalProfileScheduleInfo(String userId) async {
await _api.patch('/professional-info/$userId', profesional!.toDocument());
await _api.patch('/professionals/me', profesional!.toDocument());
NotificationsService.showSnackbar('Información actualizada');
return true;
}
+1 -1
View File
@@ -14,7 +14,7 @@ class ProfessionalProvider extends ChangeNotifier {
Future<Profesional> getProfessional(String uid) async {
try {
final data = await _api.get('/professional-info/$uid');
final data = await _api.get('/professionals/$uid');
profesional = Profesional.fromDocument(data as Map<String, dynamic>);
} catch (e) {
profesional = Profesional(
+3 -2
View File
@@ -13,8 +13,9 @@ class ProfessionalsProvider extends ChangeNotifier {
getProfessionals() async {
try {
final data = await _api.get('/users/professionals');
professionals = (data as List)
final res = await _api.get('/professionals');
final list = (res is Map ? res['data'] : res) as List;
professionals = list
.map((e) => UsuarioProfesional.fromDocument(e as Map<String, dynamic>))
.toList();
} catch (e) {
+8 -8
View File
@@ -20,7 +20,7 @@ class ServicesProvider extends ChangeNotifier {
Future<void> changeServiceStatus(String serviceId, ServiceStatus newStatus) async {
try {
await _api.patch('/services/$serviceId', {'status': enumToIntService(newStatus)});
await _api.patch('/services/$serviceId/status', {'status': enumToIntService(newStatus)});
notifyListeners();
} catch (e) {
print('Error al actualizar el estado: $e');
@@ -29,7 +29,7 @@ class ServicesProvider extends ChangeNotifier {
Future<void> changeUserScored(String serviceId) async {
try {
await _api.patch('/services/$serviceId', {'user_scored': true});
await _api.patch('/services/$serviceId/status', {'user_scored': true});
notifyListeners();
} catch (e) {
print('Error al actualizar user_scored: $e');
@@ -38,7 +38,7 @@ class ServicesProvider extends ChangeNotifier {
Future<void> changeProfessionalScored(String serviceId) async {
try {
await _api.patch('/services/$serviceId', {'professional_scored': true});
await _api.patch('/services/$serviceId/status', {'professional_scored': true});
notifyListeners();
} catch (e) {
print('Error al actualizar professional_scored: $e');
@@ -84,15 +84,15 @@ class ServicesProvider extends ChangeNotifier {
}
}
getServicesForUser(String userId) async => _loadServices('/services?user_id=$userId&status=0,1,3', forUser: true);
getServicesForUser(String userId) async => _loadServices('/services/me', forUser: true);
getServicesRequestsForProfessional(String userId) async => _loadServices('/services?professional_id=$userId&status=0', forUser: false);
getServicesRequestsForProfessional(String userId) async => _loadServices('/services/professional/requests', forUser: false);
getServicesForProfessional(String userId) async => _loadServices('/services?professional_id=$userId&status=1,3', forUser: false);
getServicesForProfessional(String userId) async => _loadServices('/services/professional', forUser: false);
getServicesHistoryForUser(String userId) async => _loadServices('/services?user_id=$userId&status=2,4,5', forUser: true);
getServicesHistoryForUser(String userId) async => _loadServices('/services/me/history', forUser: true);
getServicesHistoryForProfessional(String userId) async => _loadServices('/services?professional_id=$userId&status=2,4,5', forUser: false);
getServicesHistoryForProfessional(String userId) async => _loadServices('/services/professional/history', forUser: false);
Future<void> _loadServices(String path, {required bool forUser}) async {
try {