Register Repo
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:data_channel/data_channel.dart';
|
||||
|
||||
import '../../../common/api/api_client.dart';
|
||||
import '../../../common/api/api_failure.dart';
|
||||
import '../../../common/extension/extension.dart';
|
||||
import '../../../common/url/api_path.dart';
|
||||
import '../../../domain/auth/auth.dart';
|
||||
import '../auth_dtos.dart';
|
||||
@@ -50,4 +51,49 @@ class AuthRemoteDataProvider {
|
||||
return DC.error(AuthFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
|
||||
Future<DC<AuthFailure, RegisterDto>> register({
|
||||
required String phoneNumber,
|
||||
required String name,
|
||||
required DateTime birthDate,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _apiClient.post(
|
||||
ApiPath.register,
|
||||
data: {
|
||||
'phone_number': phoneNumber,
|
||||
'name': name,
|
||||
'birth_date': birthDate.toServerDate,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.data['success'] == false) {
|
||||
if ((response.data['errors'] as List).isNotEmpty) {
|
||||
if (response.data['errors'][0]['code'] == "900") {
|
||||
return DC.error(
|
||||
AuthFailure.dynamicErrorMessage('No. Telepon Sudah Terdaftar'),
|
||||
);
|
||||
} else {
|
||||
return DC.error(
|
||||
AuthFailure.dynamicErrorMessage(
|
||||
'Terjadi kesalahan coba lagi nanti',
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return DC.error(
|
||||
AuthFailure.dynamicErrorMessage(
|
||||
'Terjadi kesalahan coba lagi nanti',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final dto = RegisterDto.fromJson(response.data['data']);
|
||||
return DC.data(dto);
|
||||
} on ApiFailure catch (e, s) {
|
||||
log('register', name: _logName, error: e, stackTrace: s);
|
||||
return DC.error(AuthFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user