feat: Refactor bank account handling in billing and staff modules
- Introduced new bank account entities: BusinessBankAccount and StaffBankAccount. - Updated bank account adapter to handle new entities. - Removed legacy BankAccount entity and its adapter. - Implemented use case for fetching bank accounts in billing repository. - Updated BillingBloc and BillingState to include bank accounts. - Refactored PaymentMethodCard to display bank account information. - Adjusted actions widget layout for better UI consistency. - Updated staff bank account repository and use cases to utilize new entity structure. - Ensured all references to bank accounts in the codebase are updated to the new structure.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import '../../../entities/financial/bank_account/business_bank_account.dart';
|
||||
|
||||
/// Adapter for [BusinessBankAccount] to map data layer values to domain entity.
|
||||
class BusinessBankAccountAdapter {
|
||||
/// Maps primitive values to [BusinessBankAccount].
|
||||
static BusinessBankAccount fromPrimitives({
|
||||
required String id,
|
||||
required String bank,
|
||||
required String last4,
|
||||
required bool isPrimary,
|
||||
DateTime? expiryTime,
|
||||
}) {
|
||||
return BusinessBankAccount(
|
||||
id: id,
|
||||
bankName: bank,
|
||||
last4: last4,
|
||||
isPrimary: isPrimary,
|
||||
expiryTime: expiryTime,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import '../../entities/profile/bank_account.dart';
|
||||
import '../../entities/financial/bank_account/staff_bank_account.dart';
|
||||
|
||||
/// Adapter for [BankAccount] to map data layer values to domain entity.
|
||||
/// Adapter for [StaffBankAccount] to map data layer values to domain entity.
|
||||
class BankAccountAdapter {
|
||||
/// Maps primitive values to [BankAccount].
|
||||
static BankAccount fromPrimitives({
|
||||
/// Maps primitive values to [StaffBankAccount].
|
||||
static StaffBankAccount fromPrimitives({
|
||||
required String id,
|
||||
required String userId,
|
||||
required String bankName,
|
||||
@@ -13,7 +13,7 @@ class BankAccountAdapter {
|
||||
String? sortCode,
|
||||
bool? isPrimary,
|
||||
}) {
|
||||
return BankAccount(
|
||||
return StaffBankAccount(
|
||||
id: id,
|
||||
userId: userId,
|
||||
bankName: bankName,
|
||||
@@ -26,25 +26,25 @@ class BankAccountAdapter {
|
||||
);
|
||||
}
|
||||
|
||||
static BankAccountType _stringToType(String? value) {
|
||||
if (value == null) return BankAccountType.checking;
|
||||
static StaffBankAccountType _stringToType(String? value) {
|
||||
if (value == null) return StaffBankAccountType.checking;
|
||||
try {
|
||||
// Assuming backend enum names match or are uppercase
|
||||
return BankAccountType.values.firstWhere(
|
||||
(e) => e.name.toLowerCase() == value.toLowerCase(),
|
||||
orElse: () => BankAccountType.other,
|
||||
return StaffBankAccountType.values.firstWhere(
|
||||
(StaffBankAccountType e) => e.name.toLowerCase() == value.toLowerCase(),
|
||||
orElse: () => StaffBankAccountType.other,
|
||||
);
|
||||
} catch (_) {
|
||||
return BankAccountType.other;
|
||||
return StaffBankAccountType.other;
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts domain type to string for backend.
|
||||
static String typeToString(BankAccountType type) {
|
||||
static String typeToString(StaffBankAccountType type) {
|
||||
switch (type) {
|
||||
case BankAccountType.checking:
|
||||
case StaffBankAccountType.checking:
|
||||
return 'CHECKING';
|
||||
case BankAccountType.savings:
|
||||
case StaffBankAccountType.savings:
|
||||
return 'SAVINGS';
|
||||
default:
|
||||
return 'CHECKING';
|
||||
|
||||
Reference in New Issue
Block a user