mirror of
https://github.com/koloideal/Casha.git
synced 2026-08-08 09:41:13 +03:00
step
This commit is contained in:
@@ -13,9 +13,9 @@ class FeatureLimitException implements Exception {
|
||||
|
||||
class AccountRepository {
|
||||
final AppDatabase _db;
|
||||
final FeatureFlags _featureFlags;
|
||||
final FeatureFlags Function() _getFeatureFlags;
|
||||
|
||||
AccountRepository(this._db, this._featureFlags);
|
||||
AccountRepository(this._db, this._getFeatureFlags);
|
||||
|
||||
Stream<List<model.Account>> watchAll() {
|
||||
return (_db.select(_db.accounts)
|
||||
@@ -167,8 +167,9 @@ class AccountRepository {
|
||||
Future<int> add(model.Account account) async {
|
||||
final existing = await getAll();
|
||||
final nonMainCount = existing.where((a) => !a.isMain).length;
|
||||
if (nonMainCount >= _featureFlags.maxAccounts) {
|
||||
throw FeatureLimitException('Account limit reached (${_featureFlags.maxAccounts})');
|
||||
final flags = _getFeatureFlags();
|
||||
if (flags.maxAccounts != -1 && nonMainCount >= flags.maxAccounts) {
|
||||
throw FeatureLimitException('Account limit reached (${flags.maxAccounts})');
|
||||
}
|
||||
return await _db.into(_db.accounts).insert(
|
||||
AccountsCompanion.insert(
|
||||
|
||||
@@ -28,8 +28,7 @@ final transactionRepositoryProvider = Provider<TransactionRepository>((ref) {
|
||||
|
||||
final accountRepositoryProvider = Provider<AccountRepository>((ref) {
|
||||
final db = ref.watch(appDatabaseProvider);
|
||||
final flags = ref.watch(featureFlagsProvider);
|
||||
return AccountRepository(db, flags);
|
||||
return AccountRepository(db, () => ref.read(featureFlagsProvider));
|
||||
});
|
||||
|
||||
final storageServiceProvider = Provider<StorageService>((ref) {
|
||||
|
||||
Reference in New Issue
Block a user