fix profile
This commit is contained in:
@@ -39,6 +39,9 @@ class ApiService {
|
||||
static const String baseUrl = "https://api.behappybel.by/api/v1";
|
||||
static const String fileBaseUrl = "https://api.behappybel.by/";
|
||||
|
||||
/*static const String baseUrl = "https://sharing-api.sparkit.by/api/v1";
|
||||
static const String fileBaseUrl = "https://sharing-api.sparkit.by";
|
||||
*/
|
||||
final SecurityService _securityService;
|
||||
final Dio _dio;
|
||||
|
||||
@@ -172,6 +175,53 @@ class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteProfile() async {
|
||||
try {
|
||||
final response = await _dio.delete(
|
||||
"$baseUrl/client/me",
|
||||
options: await _getAuthOptions(),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = response.data;
|
||||
final profileData = data["profile"];
|
||||
if (profileData == null) return null;
|
||||
|
||||
String? parsedDate;
|
||||
if (profileData["dob"] != null) {
|
||||
try {
|
||||
parsedDate = DateFormat(
|
||||
'dd.MM.yyyy',
|
||||
).format(DateTime.parse(profileData["dob"]));
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
final int? avatarId = profileData["avatarId"];
|
||||
String? avatarUrl;
|
||||
|
||||
if (avatarId != null && profileData["avatar"] != null) {
|
||||
final String? avatarPath = profileData["avatar"]["path"];
|
||||
if (avatarPath != null && avatarPath.isNotEmpty) {
|
||||
avatarUrl = Uri.parse(fileBaseUrl).resolve(avatarPath).toString();
|
||||
}
|
||||
}
|
||||
|
||||
dynamic balanceRaw = profileData["balance"];
|
||||
double? balance;
|
||||
|
||||
if (balanceRaw is num) {
|
||||
balance = balanceRaw.toDouble();
|
||||
} else if (balanceRaw is String) {
|
||||
balance = double.tryParse(balanceRaw);
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<PaymentCard>> getPaymentCards() async {
|
||||
final response = await _dio.get(
|
||||
"$baseUrl/client/me",
|
||||
|
||||
Reference in New Issue
Block a user