bank account connect to dataconnect with staffid

This commit is contained in:
José Salazar
2026-01-26 10:59:11 -05:00
parent 0ba5a9ae16
commit 2f5c607996
2 changed files with 13 additions and 70 deletions

View File

@@ -143,10 +143,6 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
}
final String email = user?.email ?? '';
if (mode != AuthMode.signup && email.isEmpty) {
await firebaseAuth.signOut();
throw Exception('User email is missing in profile data.');
}
//TO-DO: create(registration) user and staff account
//TO-DO: save user data locally

View File

@@ -19,72 +19,15 @@ class BankAccountRepositoryImpl implements BankAccountRepository {
Future<List<BankAccount>> getAccounts() async {
final auth.User? user = firebaseAuth.currentUser;
if (user == null) throw Exception('User not authenticated');
final String? staffId = StaffSessionStore.instance.session?.staff?.id;
if (staffId == null || staffId.isEmpty) {
throw Exception('Staff profile is missing.');
}
// return some mock data for now
return [
BankAccount(
id: '1',
userId: user.uid,
bankName: 'Mock Bank',
accountNumber: '****1234',
accountName: 'My Checking Account',
type: BankAccountType.checking,
last4: '1234',
isPrimary: true,
),
BankAccount(
id: '2',
userId: user.uid,
bankName: 'Mock Bank',
accountNumber: '****5678',
accountName: 'My Savings Account',
type: BankAccountType.savings,
last4: '5678',
isPrimary: false,
),
BankAccount(
id: '3',
userId: user.uid,
bankName: 'Mock Bank',
accountNumber: '****1234',
accountName: 'My Checking Account',
type: BankAccountType.checking,
last4: '1234',
isPrimary: true,
),
BankAccount(
id: '4',
userId: user.uid,
bankName: 'Mock Bank',
accountNumber: '****5678',
accountName: 'My Savings Account',
type: BankAccountType.savings,
last4: '5678',
isPrimary: false,
),
BankAccount(
id: '5',
userId: user.uid,
bankName: 'Mock Bank',
accountNumber: '****1234',
accountName: 'My Checking Account',
type: BankAccountType.checking,
last4: '1234',
isPrimary: true,
),
BankAccount(
id: '6',
userId: user.uid,
bankName: 'Mock Bank',
accountNumber: '****5678',
accountName: 'My Savings Account',
type: BankAccountType.savings,
last4: '5678',
isPrimary: false,
),
];
final QueryResult<GetAccountsByOwnerIdData, GetAccountsByOwnerIdVariables> result = await dataConnect.getAccountsByOwnerId(ownerId: user.uid).execute();
final QueryResult<GetAccountsByOwnerIdData, GetAccountsByOwnerIdVariables>
result = await dataConnect
.getAccountsByOwnerId(ownerId: staffId)
.execute();
return result.data.accounts.map((GetAccountsByOwnerIdAccounts account) {
return BankAccount(
@@ -104,12 +47,16 @@ class BankAccountRepositoryImpl implements BankAccountRepository {
Future<void> addAccount(BankAccount account) async {
final auth.User? user = firebaseAuth.currentUser;
if (user == null) throw Exception('User not authenticated');
final String? staffId = StaffSessionStore.instance.session?.staff?.id;
if (staffId == null || staffId.isEmpty) {
throw Exception('Staff profile is missing.');
}
await dataConnect.createAccount(
bank: account.bankName,
type: _mapDomainType(account.type),
last4: account.last4 ?? account.accountNumber.substring(account.accountNumber.length - 4),
ownerId: user.uid,
ownerId: staffId,
).isPrimary(account.isPrimary).execute();
}