account working

This commit is contained in:
José Salazar
2026-01-26 13:57:04 -05:00
parent 42a11590f1
commit 1934d4caab
13 changed files with 19419 additions and 19282 deletions

View File

@@ -1,16 +1,16 @@
# Basic Usage
```dart
ExampleConnector.instance.CreateUser(createUserVariables).execute();
ExampleConnector.instance.UpdateUser(updateUserVariables).execute();
ExampleConnector.instance.DeleteUser(deleteUserVariables).execute();
ExampleConnector.instance.listVendorRates().execute();
ExampleConnector.instance.getVendorRateById(getVendorRateByIdVariables).execute();
ExampleConnector.instance.listApplications().execute();
ExampleConnector.instance.getApplicationById(getApplicationByIdVariables).execute();
ExampleConnector.instance.getApplicationsByShiftId(getApplicationsByShiftIdVariables).execute();
ExampleConnector.instance.getApplicationsByShiftIdAndStatus(getApplicationsByShiftIdAndStatusVariables).execute();
ExampleConnector.instance.getApplicationsByStaffId(getApplicationsByStaffIdVariables).execute();
ExampleConnector.instance.createWorkforce(createWorkforceVariables).execute();
ExampleConnector.instance.updateWorkforce(updateWorkforceVariables).execute();
ExampleConnector.instance.deactivateWorkforce(deactivateWorkforceVariables).execute();
ExampleConnector.instance.listInvoices(listInvoicesVariables).execute();
ExampleConnector.instance.getInvoiceById(getInvoiceByIdVariables).execute();
ExampleConnector.instance.listInvoicesByVendorId(listInvoicesByVendorIdVariables).execute();
ExampleConnector.instance.listInvoicesByBusinessId(listInvoicesByBusinessIdVariables).execute();
ExampleConnector.instance.listInvoicesByOrderId(listInvoicesByOrderIdVariables).execute();
ExampleConnector.instance.listInvoicesByStatus(listInvoicesByStatusVariables).execute();
ExampleConnector.instance.filterInvoices(filterInvoicesVariables).execute();
```
@@ -23,8 +23,8 @@ Optional fields can be discovered based on classes that have `Optional` object t
This is an example of a mutation with an optional field:
```dart
await ExampleConnector.instance.listStaffAvailabilitiesByDay({ ... })
.offset(...)
await ExampleConnector.instance.updateVendor({ ... })
.companyName(...)
.execute();
```

View File

@@ -6,11 +6,21 @@ class CreateAccountVariablesBuilder {
String last4;
Optional<bool> _isPrimary = Optional.optional(nativeFromJson, nativeToJson);
String ownerId;
Optional<String> _accountNumber = Optional.optional(nativeFromJson, nativeToJson);
Optional<String> _routeNumber = Optional.optional(nativeFromJson, nativeToJson);
final FirebaseDataConnect _dataConnect; CreateAccountVariablesBuilder isPrimary(bool? t) {
_isPrimary.value = t;
return this;
}
CreateAccountVariablesBuilder accountNumber(String? t) {
_accountNumber.value = t;
return this;
}
CreateAccountVariablesBuilder routeNumber(String? t) {
_routeNumber.value = t;
return this;
}
CreateAccountVariablesBuilder(this._dataConnect, {required this.bank,required this.type,required this.last4,required this.ownerId,});
Deserializer<CreateAccountData> dataDeserializer = (dynamic json) => CreateAccountData.fromJson(jsonDecode(json));
@@ -20,7 +30,7 @@ class CreateAccountVariablesBuilder {
}
MutationRef<CreateAccountData, CreateAccountVariables> ref() {
CreateAccountVariables vars= CreateAccountVariables(bank: bank,type: type,last4: last4,isPrimary: _isPrimary,ownerId: ownerId,);
CreateAccountVariables vars= CreateAccountVariables(bank: bank,type: type,last4: last4,isPrimary: _isPrimary,ownerId: ownerId,accountNumber: _accountNumber,routeNumber: _routeNumber,);
return _dataConnect.mutation("createAccount", dataDeserializer, varsSerializer, vars);
}
}
@@ -100,6 +110,8 @@ class CreateAccountVariables {
final String last4;
late final Optional<bool>isPrimary;
final String ownerId;
late final Optional<String>accountNumber;
late final Optional<String>routeNumber;
@Deprecated('fromJson is deprecated for Variable classes as they are no longer required for deserialization.')
CreateAccountVariables.fromJson(Map<String, dynamic> json):
@@ -116,6 +128,14 @@ class CreateAccountVariables {
isPrimary.value = json['isPrimary'] == null ? null : nativeFromJson<bool>(json['isPrimary']);
accountNumber = Optional.optional(nativeFromJson, nativeToJson);
accountNumber.value = json['accountNumber'] == null ? null : nativeFromJson<String>(json['accountNumber']);
routeNumber = Optional.optional(nativeFromJson, nativeToJson);
routeNumber.value = json['routeNumber'] == null ? null : nativeFromJson<String>(json['routeNumber']);
}
@override
bool operator ==(Object other) {
@@ -131,11 +151,13 @@ class CreateAccountVariables {
type == otherTyped.type &&
last4 == otherTyped.last4 &&
isPrimary == otherTyped.isPrimary &&
ownerId == otherTyped.ownerId;
ownerId == otherTyped.ownerId &&
accountNumber == otherTyped.accountNumber &&
routeNumber == otherTyped.routeNumber;
}
@override
int get hashCode => Object.hashAll([bank.hashCode, type.hashCode, last4.hashCode, isPrimary.hashCode, ownerId.hashCode]);
int get hashCode => Object.hashAll([bank.hashCode, type.hashCode, last4.hashCode, isPrimary.hashCode, ownerId.hashCode, accountNumber.hashCode, routeNumber.hashCode]);
Map<String, dynamic> toJson() {
@@ -149,6 +171,12 @@ class CreateAccountVariables {
json['isPrimary'] = isPrimary.toJson();
}
json['ownerId'] = nativeToJson<String>(ownerId);
if(accountNumber.state == OptionalState.set) {
json['accountNumber'] = accountNumber.toJson();
}
if(routeNumber.state == OptionalState.set) {
json['routeNumber'] = routeNumber.toJson();
}
return json;
}
@@ -158,6 +186,8 @@ class CreateAccountVariables {
required this.last4,
required this.isPrimary,
required this.ownerId,
required this.accountNumber,
required this.routeNumber,
});
}

View File

@@ -45,6 +45,8 @@ class FilterAccountsAccounts {
final String last4;
final bool? isPrimary;
final String ownerId;
final String? accountNumber;
final String? routeNumber;
FilterAccountsAccounts.fromJson(dynamic json):
id = nativeFromJson<String>(json['id']),
@@ -52,7 +54,9 @@ class FilterAccountsAccounts {
type = accountTypeDeserializer(json['type']),
last4 = nativeFromJson<String>(json['last4']),
isPrimary = json['isPrimary'] == null ? null : nativeFromJson<bool>(json['isPrimary']),
ownerId = nativeFromJson<String>(json['ownerId']);
ownerId = nativeFromJson<String>(json['ownerId']),
accountNumber = json['accountNumber'] == null ? null : nativeFromJson<String>(json['accountNumber']),
routeNumber = json['routeNumber'] == null ? null : nativeFromJson<String>(json['routeNumber']);
@override
bool operator ==(Object other) {
if(identical(this, other)) {
@@ -68,11 +72,13 @@ class FilterAccountsAccounts {
type == otherTyped.type &&
last4 == otherTyped.last4 &&
isPrimary == otherTyped.isPrimary &&
ownerId == otherTyped.ownerId;
ownerId == otherTyped.ownerId &&
accountNumber == otherTyped.accountNumber &&
routeNumber == otherTyped.routeNumber;
}
@override
int get hashCode => Object.hashAll([id.hashCode, bank.hashCode, type.hashCode, last4.hashCode, isPrimary.hashCode, ownerId.hashCode]);
int get hashCode => Object.hashAll([id.hashCode, bank.hashCode, type.hashCode, last4.hashCode, isPrimary.hashCode, ownerId.hashCode, accountNumber.hashCode, routeNumber.hashCode]);
Map<String, dynamic> toJson() {
@@ -87,6 +93,12 @@ class FilterAccountsAccounts {
json['isPrimary'] = nativeToJson<bool?>(isPrimary);
}
json['ownerId'] = nativeToJson<String>(ownerId);
if (accountNumber != null) {
json['accountNumber'] = nativeToJson<String?>(accountNumber);
}
if (routeNumber != null) {
json['routeNumber'] = nativeToJson<String?>(routeNumber);
}
return json;
}
@@ -97,6 +109,8 @@ class FilterAccountsAccounts {
required this.last4,
this.isPrimary,
required this.ownerId,
this.accountNumber,
this.routeNumber,
});
}

View File

@@ -25,9 +25,9 @@ class GetAccountByIdAccount {
final String last4;
final bool? isPrimary;
final String ownerId;
final String? accountNumber;
final String? routeNumber;
final Timestamp? createdAt;
final Timestamp? updatedAt;
final String? createdBy;
GetAccountByIdAccount.fromJson(dynamic json):
id = nativeFromJson<String>(json['id']),
@@ -36,9 +36,9 @@ class GetAccountByIdAccount {
last4 = nativeFromJson<String>(json['last4']),
isPrimary = json['isPrimary'] == null ? null : nativeFromJson<bool>(json['isPrimary']),
ownerId = nativeFromJson<String>(json['ownerId']),
createdAt = json['createdAt'] == null ? null : Timestamp.fromJson(json['createdAt']),
updatedAt = json['updatedAt'] == null ? null : Timestamp.fromJson(json['updatedAt']),
createdBy = json['createdBy'] == null ? null : nativeFromJson<String>(json['createdBy']);
accountNumber = json['accountNumber'] == null ? null : nativeFromJson<String>(json['accountNumber']),
routeNumber = json['routeNumber'] == null ? null : nativeFromJson<String>(json['routeNumber']),
createdAt = json['createdAt'] == null ? null : Timestamp.fromJson(json['createdAt']);
@override
bool operator ==(Object other) {
if(identical(this, other)) {
@@ -55,13 +55,13 @@ class GetAccountByIdAccount {
last4 == otherTyped.last4 &&
isPrimary == otherTyped.isPrimary &&
ownerId == otherTyped.ownerId &&
createdAt == otherTyped.createdAt &&
updatedAt == otherTyped.updatedAt &&
createdBy == otherTyped.createdBy;
accountNumber == otherTyped.accountNumber &&
routeNumber == otherTyped.routeNumber &&
createdAt == otherTyped.createdAt;
}
@override
int get hashCode => Object.hashAll([id.hashCode, bank.hashCode, type.hashCode, last4.hashCode, isPrimary.hashCode, ownerId.hashCode, createdAt.hashCode, updatedAt.hashCode, createdBy.hashCode]);
int get hashCode => Object.hashAll([id.hashCode, bank.hashCode, type.hashCode, last4.hashCode, isPrimary.hashCode, ownerId.hashCode, accountNumber.hashCode, routeNumber.hashCode, createdAt.hashCode]);
Map<String, dynamic> toJson() {
@@ -76,15 +76,15 @@ class GetAccountByIdAccount {
json['isPrimary'] = nativeToJson<bool?>(isPrimary);
}
json['ownerId'] = nativeToJson<String>(ownerId);
if (accountNumber != null) {
json['accountNumber'] = nativeToJson<String?>(accountNumber);
}
if (routeNumber != null) {
json['routeNumber'] = nativeToJson<String?>(routeNumber);
}
if (createdAt != null) {
json['createdAt'] = createdAt!.toJson();
}
if (updatedAt != null) {
json['updatedAt'] = updatedAt!.toJson();
}
if (createdBy != null) {
json['createdBy'] = nativeToJson<String?>(createdBy);
}
return json;
}
@@ -95,9 +95,9 @@ class GetAccountByIdAccount {
required this.last4,
this.isPrimary,
required this.ownerId,
this.accountNumber,
this.routeNumber,
this.createdAt,
this.updatedAt,
this.createdBy,
});
}

View File

@@ -25,9 +25,9 @@ class GetAccountsByOwnerIdAccounts {
final String last4;
final bool? isPrimary;
final String ownerId;
final String? accountNumber;
final String? routeNumber;
final Timestamp? createdAt;
final Timestamp? updatedAt;
final String? createdBy;
GetAccountsByOwnerIdAccounts.fromJson(dynamic json):
id = nativeFromJson<String>(json['id']),
@@ -36,9 +36,9 @@ class GetAccountsByOwnerIdAccounts {
last4 = nativeFromJson<String>(json['last4']),
isPrimary = json['isPrimary'] == null ? null : nativeFromJson<bool>(json['isPrimary']),
ownerId = nativeFromJson<String>(json['ownerId']),
createdAt = json['createdAt'] == null ? null : Timestamp.fromJson(json['createdAt']),
updatedAt = json['updatedAt'] == null ? null : Timestamp.fromJson(json['updatedAt']),
createdBy = json['createdBy'] == null ? null : nativeFromJson<String>(json['createdBy']);
accountNumber = json['accountNumber'] == null ? null : nativeFromJson<String>(json['accountNumber']),
routeNumber = json['routeNumber'] == null ? null : nativeFromJson<String>(json['routeNumber']),
createdAt = json['createdAt'] == null ? null : Timestamp.fromJson(json['createdAt']);
@override
bool operator ==(Object other) {
if(identical(this, other)) {
@@ -55,13 +55,13 @@ class GetAccountsByOwnerIdAccounts {
last4 == otherTyped.last4 &&
isPrimary == otherTyped.isPrimary &&
ownerId == otherTyped.ownerId &&
createdAt == otherTyped.createdAt &&
updatedAt == otherTyped.updatedAt &&
createdBy == otherTyped.createdBy;
accountNumber == otherTyped.accountNumber &&
routeNumber == otherTyped.routeNumber &&
createdAt == otherTyped.createdAt;
}
@override
int get hashCode => Object.hashAll([id.hashCode, bank.hashCode, type.hashCode, last4.hashCode, isPrimary.hashCode, ownerId.hashCode, createdAt.hashCode, updatedAt.hashCode, createdBy.hashCode]);
int get hashCode => Object.hashAll([id.hashCode, bank.hashCode, type.hashCode, last4.hashCode, isPrimary.hashCode, ownerId.hashCode, accountNumber.hashCode, routeNumber.hashCode, createdAt.hashCode]);
Map<String, dynamic> toJson() {
@@ -76,15 +76,15 @@ class GetAccountsByOwnerIdAccounts {
json['isPrimary'] = nativeToJson<bool?>(isPrimary);
}
json['ownerId'] = nativeToJson<String>(ownerId);
if (accountNumber != null) {
json['accountNumber'] = nativeToJson<String?>(accountNumber);
}
if (routeNumber != null) {
json['routeNumber'] = nativeToJson<String?>(routeNumber);
}
if (createdAt != null) {
json['createdAt'] = createdAt!.toJson();
}
if (updatedAt != null) {
json['updatedAt'] = updatedAt!.toJson();
}
if (createdBy != null) {
json['createdBy'] = nativeToJson<String?>(createdBy);
}
return json;
}
@@ -95,9 +95,9 @@ class GetAccountsByOwnerIdAccounts {
required this.last4,
this.isPrimary,
required this.ownerId,
this.accountNumber,
this.routeNumber,
this.createdAt,
this.updatedAt,
this.createdBy,
});
}

View File

@@ -24,9 +24,9 @@ class ListAccountsAccounts {
final String last4;
final bool? isPrimary;
final String ownerId;
final String? accountNumber;
final String? routeNumber;
final Timestamp? createdAt;
final Timestamp? updatedAt;
final String? createdBy;
ListAccountsAccounts.fromJson(dynamic json):
id = nativeFromJson<String>(json['id']),
@@ -35,9 +35,9 @@ class ListAccountsAccounts {
last4 = nativeFromJson<String>(json['last4']),
isPrimary = json['isPrimary'] == null ? null : nativeFromJson<bool>(json['isPrimary']),
ownerId = nativeFromJson<String>(json['ownerId']),
createdAt = json['createdAt'] == null ? null : Timestamp.fromJson(json['createdAt']),
updatedAt = json['updatedAt'] == null ? null : Timestamp.fromJson(json['updatedAt']),
createdBy = json['createdBy'] == null ? null : nativeFromJson<String>(json['createdBy']);
accountNumber = json['accountNumber'] == null ? null : nativeFromJson<String>(json['accountNumber']),
routeNumber = json['routeNumber'] == null ? null : nativeFromJson<String>(json['routeNumber']),
createdAt = json['createdAt'] == null ? null : Timestamp.fromJson(json['createdAt']);
@override
bool operator ==(Object other) {
if(identical(this, other)) {
@@ -54,13 +54,13 @@ class ListAccountsAccounts {
last4 == otherTyped.last4 &&
isPrimary == otherTyped.isPrimary &&
ownerId == otherTyped.ownerId &&
createdAt == otherTyped.createdAt &&
updatedAt == otherTyped.updatedAt &&
createdBy == otherTyped.createdBy;
accountNumber == otherTyped.accountNumber &&
routeNumber == otherTyped.routeNumber &&
createdAt == otherTyped.createdAt;
}
@override
int get hashCode => Object.hashAll([id.hashCode, bank.hashCode, type.hashCode, last4.hashCode, isPrimary.hashCode, ownerId.hashCode, createdAt.hashCode, updatedAt.hashCode, createdBy.hashCode]);
int get hashCode => Object.hashAll([id.hashCode, bank.hashCode, type.hashCode, last4.hashCode, isPrimary.hashCode, ownerId.hashCode, accountNumber.hashCode, routeNumber.hashCode, createdAt.hashCode]);
Map<String, dynamic> toJson() {
@@ -75,15 +75,15 @@ class ListAccountsAccounts {
json['isPrimary'] = nativeToJson<bool?>(isPrimary);
}
json['ownerId'] = nativeToJson<String>(ownerId);
if (accountNumber != null) {
json['accountNumber'] = nativeToJson<String?>(accountNumber);
}
if (routeNumber != null) {
json['routeNumber'] = nativeToJson<String?>(routeNumber);
}
if (createdAt != null) {
json['createdAt'] = createdAt!.toJson();
}
if (updatedAt != null) {
json['updatedAt'] = updatedAt!.toJson();
}
if (createdBy != null) {
json['createdBy'] = nativeToJson<String?>(createdBy);
}
return json;
}
@@ -94,9 +94,9 @@ class ListAccountsAccounts {
required this.last4,
this.isPrimary,
required this.ownerId,
this.accountNumber,
this.routeNumber,
this.createdAt,
this.updatedAt,
this.createdBy,
});
}

View File

@@ -6,6 +6,8 @@ class UpdateAccountVariablesBuilder {
Optional<AccountType> _type = Optional.optional((data) => AccountType.values.byName(data), enumSerializer);
Optional<String> _last4 = Optional.optional(nativeFromJson, nativeToJson);
Optional<bool> _isPrimary = Optional.optional(nativeFromJson, nativeToJson);
Optional<String> _accountNumber = Optional.optional(nativeFromJson, nativeToJson);
Optional<String> _routeNumber = Optional.optional(nativeFromJson, nativeToJson);
final FirebaseDataConnect _dataConnect; UpdateAccountVariablesBuilder bank(String? t) {
_bank.value = t;
@@ -23,6 +25,14 @@ class UpdateAccountVariablesBuilder {
_isPrimary.value = t;
return this;
}
UpdateAccountVariablesBuilder accountNumber(String? t) {
_accountNumber.value = t;
return this;
}
UpdateAccountVariablesBuilder routeNumber(String? t) {
_routeNumber.value = t;
return this;
}
UpdateAccountVariablesBuilder(this._dataConnect, {required this.id,});
Deserializer<UpdateAccountData> dataDeserializer = (dynamic json) => UpdateAccountData.fromJson(jsonDecode(json));
@@ -32,7 +42,7 @@ class UpdateAccountVariablesBuilder {
}
MutationRef<UpdateAccountData, UpdateAccountVariables> ref() {
UpdateAccountVariables vars= UpdateAccountVariables(id: id,bank: _bank,type: _type,last4: _last4,isPrimary: _isPrimary,);
UpdateAccountVariables vars= UpdateAccountVariables(id: id,bank: _bank,type: _type,last4: _last4,isPrimary: _isPrimary,accountNumber: _accountNumber,routeNumber: _routeNumber,);
return _dataConnect.mutation("updateAccount", dataDeserializer, varsSerializer, vars);
}
}
@@ -114,6 +124,8 @@ class UpdateAccountVariables {
late final Optional<AccountType>type;
late final Optional<String>last4;
late final Optional<bool>isPrimary;
late final Optional<String>accountNumber;
late final Optional<String>routeNumber;
@Deprecated('fromJson is deprecated for Variable classes as they are no longer required for deserialization.')
UpdateAccountVariables.fromJson(Map<String, dynamic> json):
@@ -136,6 +148,14 @@ class UpdateAccountVariables {
isPrimary = Optional.optional(nativeFromJson, nativeToJson);
isPrimary.value = json['isPrimary'] == null ? null : nativeFromJson<bool>(json['isPrimary']);
accountNumber = Optional.optional(nativeFromJson, nativeToJson);
accountNumber.value = json['accountNumber'] == null ? null : nativeFromJson<String>(json['accountNumber']);
routeNumber = Optional.optional(nativeFromJson, nativeToJson);
routeNumber.value = json['routeNumber'] == null ? null : nativeFromJson<String>(json['routeNumber']);
}
@override
bool operator ==(Object other) {
@@ -151,11 +171,13 @@ class UpdateAccountVariables {
bank == otherTyped.bank &&
type == otherTyped.type &&
last4 == otherTyped.last4 &&
isPrimary == otherTyped.isPrimary;
isPrimary == otherTyped.isPrimary &&
accountNumber == otherTyped.accountNumber &&
routeNumber == otherTyped.routeNumber;
}
@override
int get hashCode => Object.hashAll([id.hashCode, bank.hashCode, type.hashCode, last4.hashCode, isPrimary.hashCode]);
int get hashCode => Object.hashAll([id.hashCode, bank.hashCode, type.hashCode, last4.hashCode, isPrimary.hashCode, accountNumber.hashCode, routeNumber.hashCode]);
Map<String, dynamic> toJson() {
@@ -173,6 +195,12 @@ class UpdateAccountVariables {
if(isPrimary.state == OptionalState.set) {
json['isPrimary'] = isPrimary.toJson();
}
if(accountNumber.state == OptionalState.set) {
json['accountNumber'] = accountNumber.toJson();
}
if(routeNumber.state == OptionalState.set) {
json['routeNumber'] = routeNumber.toJson();
}
return json;
}
@@ -182,6 +210,8 @@ class UpdateAccountVariables {
required this.type,
required this.last4,
required this.isPrimary,
required this.accountNumber,
required this.routeNumber,
});
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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,

View File

@@ -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,
),