Can change default account

This commit is contained in:
2025-04-07 21:42:35 +02:00
parent 1977b5209c
commit 90bb4db806
3 changed files with 30 additions and 1 deletions

View File

@ -68,6 +68,25 @@ pub async fn get_list_user(id: UserID) -> anyhow::Result<Vec<Account>> {
.get_results(&mut db()?)?)
}
/// Change the default account of a user
pub async fn set_default(user_id: UserID, account_id: AccountID) -> anyhow::Result<()> {
diesel::update(accounts::dsl::accounts.filter(accounts::dsl::user_id.eq(user_id.0)))
.set((accounts::dsl::default_account.eq(false),))
.execute(&mut db()?)?;
diesel::update(
accounts::dsl::accounts.filter(
accounts::dsl::user_id
.eq(user_id.0)
.and(accounts::dsl::id.eq(account_id.0)),
),
)
.set((accounts::dsl::default_account.eq(true),))
.execute(&mut db()?)?;
Ok(())
}
/// Delete an account
pub async fn delete(id: AccountID) -> anyhow::Result<()> {
diesel::delete(accounts::dsl::accounts.filter(accounts::dsl::id.eq(id.0)))