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:
co-authored by
Claude Sonnet 4.6
parent
60216fd0e3
commit
0ecca498ad
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user