account working
This commit is contained in:
@@ -95,6 +95,8 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
|
||||
).execute();
|
||||
final GetUserByIdUser? user = response.data.user;
|
||||
|
||||
GetStaffByUserIdStaffs? staffRecord;
|
||||
|
||||
if (mode == AuthMode.signup) {
|
||||
if (user == null) {
|
||||
await dataConnect
|
||||
@@ -140,6 +142,7 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
|
||||
'Your account is not registered yet. Please register first.',
|
||||
);
|
||||
}
|
||||
staffRecord = staffResponse.data.staffs.first;
|
||||
}
|
||||
|
||||
final String email = user?.email ?? '';
|
||||
@@ -152,8 +155,21 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
|
||||
phone: firebaseUser.phoneNumber,
|
||||
role: user?.role.stringValue ?? 'USER',
|
||||
);
|
||||
final domain.Staff? domainStaff = staffRecord == null
|
||||
? null
|
||||
: domain.Staff(
|
||||
id: staffRecord.id,
|
||||
authProviderId: staffRecord.userId,
|
||||
name: staffRecord.fullName,
|
||||
email: staffRecord.email ?? '',
|
||||
phone: staffRecord.phone,
|
||||
status: domain.StaffStatus.completedProfile,
|
||||
address: staffRecord.addres,
|
||||
avatar: staffRecord.photoUrl,
|
||||
livePhoto: null,
|
||||
);
|
||||
StaffSessionStore.instance.setSession(
|
||||
StaffSession(user: domainUser, staff: null),
|
||||
StaffSession(user: domainUser, staff: domainStaff),
|
||||
);
|
||||
return domainUser;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ class BankAccountRepositoryImpl implements BankAccountRepository {
|
||||
if (user == null) throw Exception('User not authenticated');
|
||||
final String? staffId = StaffSessionStore.instance.session?.staff?.id;
|
||||
if (staffId == null || staffId.isEmpty) {
|
||||
print('BankAccount getAccounts: missing staffId userId=${user.uid} session=${StaffSessionStore.instance.session}');
|
||||
throw Exception('Staff profile is missing.');
|
||||
}
|
||||
|
||||
@@ -34,9 +35,10 @@ class BankAccountRepositoryImpl implements BankAccountRepository {
|
||||
id: account.id,
|
||||
userId: account.ownerId,
|
||||
bankName: account.bank,
|
||||
accountNumber: account.last4, // Using last4 as account number representation for now
|
||||
accountNumber: account.accountNumber ?? '',
|
||||
last4: account.last4,
|
||||
accountName: '', // Not returned by API
|
||||
sortCode: account.routeNumber,
|
||||
type: _mapAccountType(account.type),
|
||||
isPrimary: account.isPrimary ?? false,
|
||||
);
|
||||
@@ -49,15 +51,23 @@ class BankAccountRepositoryImpl implements BankAccountRepository {
|
||||
if (user == null) throw Exception('User not authenticated');
|
||||
final String? staffId = StaffSessionStore.instance.session?.staff?.id;
|
||||
if (staffId == null || staffId.isEmpty) {
|
||||
print('BankAccount addAccount: missing staffId userId=${user.uid} session=${StaffSessionStore.instance.session}');
|
||||
throw Exception('Staff profile is missing.');
|
||||
}
|
||||
|
||||
final QueryResult<GetAccountsByOwnerIdData, GetAccountsByOwnerIdVariables>
|
||||
existingAccounts = await dataConnect
|
||||
.getAccountsByOwnerId(ownerId: staffId)
|
||||
.execute();
|
||||
final bool hasAccounts = existingAccounts.data.accounts.isNotEmpty;
|
||||
final bool isPrimary = !hasAccounts;
|
||||
|
||||
await dataConnect.createAccount(
|
||||
bank: account.bankName,
|
||||
type: _mapDomainType(account.type),
|
||||
last4: account.last4 ?? account.accountNumber.substring(account.accountNumber.length - 4),
|
||||
last4: _safeLast4(account.last4, account.accountNumber),
|
||||
ownerId: staffId,
|
||||
).isPrimary(account.isPrimary).execute();
|
||||
).isPrimary(isPrimary).accountNumber(account.accountNumber).routeNumber(account.sortCode).execute();
|
||||
}
|
||||
|
||||
BankAccountType _mapAccountType(EnumValue<AccountType> type) {
|
||||
@@ -82,4 +92,16 @@ class BankAccountRepositoryImpl implements BankAccountRepository {
|
||||
return AccountType.CHECKING; // Default fallback
|
||||
}
|
||||
}
|
||||
|
||||
String _safeLast4(String? last4, String accountNumber) {
|
||||
if (last4 != null && last4.isNotEmpty) {
|
||||
return last4;
|
||||
}
|
||||
if (accountNumber.isEmpty) {
|
||||
return '';
|
||||
}
|
||||
return accountNumber.length > 4
|
||||
? accountNumber.substring(accountNumber.length - 4)
|
||||
: accountNumber;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ class BankAccountCubit extends Cubit<BankAccountState> {
|
||||
bankName: 'New Bank', // Mock
|
||||
accountNumber: accountNumber,
|
||||
accountName: '',
|
||||
sortCode: routingNumber,
|
||||
type: type == 'CHECKING' ? BankAccountType.checking : BankAccountType.savings,
|
||||
last4: accountNumber.length > 4 ? accountNumber.substring(accountNumber.length - 4) : accountNumber,
|
||||
isPrimary: false,
|
||||
|
||||
@@ -206,7 +206,11 @@ class BankAccountPage extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
strings.account_ending(last4: account.last4),
|
||||
strings.account_ending(
|
||||
last4: account.last4?.isNotEmpty == true
|
||||
? account.last4!
|
||||
: '----',
|
||||
),
|
||||
style: UiTypography.body2r.copyWith( // Was body2
|
||||
color: UiColors.textSecondary,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user