Can change default account
This commit is contained in:
@ -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)))
|
||||
|
Reference in New Issue
Block a user