Implement account deletion
This commit is contained in:
parent
cbe2d5a556
commit
71993c2686
@ -179,7 +179,16 @@ class OkaneDatabase extends _$OkaneDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
@DriftAccessor(tables: [Accounts])
|
||||
@DriftAccessor(
|
||||
tables: [
|
||||
Accounts,
|
||||
Transactions,
|
||||
TransactionTemplates,
|
||||
RecurringTransactions,
|
||||
Budgets,
|
||||
Beneficiaries,
|
||||
],
|
||||
)
|
||||
class AccountsDao extends DatabaseAccessor<OkaneDatabase>
|
||||
with _$AccountsDaoMixin {
|
||||
AccountsDao(OkaneDatabase db) : super(db);
|
||||
@ -195,6 +204,22 @@ class AccountsDao extends DatabaseAccessor<OkaneDatabase>
|
||||
Future<int> upsertAccount(AccountsCompanion account) {
|
||||
return into(accounts).insertOnConflictUpdate(account);
|
||||
}
|
||||
|
||||
Future<void> removeAccount(Account account) async {
|
||||
// Delete dependent data
|
||||
await (delete(transactions)
|
||||
..where((t) => t.accountId.equals(account.id))).go();
|
||||
await (delete(recurringTransactions)
|
||||
..where((r) => r.accountId.equals(account.id))).go();
|
||||
await (delete(transactionTemplates)
|
||||
..where((t) => t.accountId.equals(account.id))).go();
|
||||
await (delete(budgets)..where((b) => b.accountId.equals(account.id))).go();
|
||||
await (delete(beneficiaries)
|
||||
..where((b) => b.accountId.equals(account.id))).go();
|
||||
|
||||
// Delete the account
|
||||
await (delete(accounts)..where((a) => a.id.equals(account.id))).go();
|
||||
}
|
||||
}
|
||||
|
||||
enum TransactionQueryDateOption { thisMonth }
|
||||
|
@ -8190,6 +8190,15 @@ class $OkaneDatabaseManager {
|
||||
|
||||
mixin _$AccountsDaoMixin on DatabaseAccessor<OkaneDatabase> {
|
||||
$AccountsTable get accounts => attachedDatabase.accounts;
|
||||
$ExpenseCategoriesTable get expenseCategories =>
|
||||
attachedDatabase.expenseCategories;
|
||||
$BeneficiariesTable get beneficiaries => attachedDatabase.beneficiaries;
|
||||
$TransactionsTable get transactions => attachedDatabase.transactions;
|
||||
$TransactionTemplatesTable get transactionTemplates =>
|
||||
attachedDatabase.transactionTemplates;
|
||||
$RecurringTransactionsTable get recurringTransactions =>
|
||||
attachedDatabase.recurringTransactions;
|
||||
$BudgetsTable get budgets => attachedDatabase.budgets;
|
||||
}
|
||||
mixin _$BeneficiariesDaoMixin on DatabaseAccessor<OkaneDatabase> {
|
||||
$AccountsTable get accounts => attachedDatabase.accounts;
|
||||
|
@ -193,8 +193,7 @@ class CoreCubit extends Cubit<CoreState> {
|
||||
|
||||
cancelStreams();
|
||||
try {
|
||||
// TODO
|
||||
//await db.deleteAccount(account);
|
||||
await GetIt.I.get<OkaneDatabase>().accountsDao.removeAccount(account);
|
||||
} finally {
|
||||
emit(state.copyWith(isDeletingAccount: false));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user