Added Account::delete_all method

This commit is contained in:
StNicolay 2023-05-09 20:32:07 +03:00
parent 3db99a3626
commit b326aa696d
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D
2 changed files with 11 additions and 5 deletions

View File

@ -145,4 +145,13 @@ impl Entity {
.await .await
.map_err(Into::into) .map_err(Into::into)
} }
/// Deletes all the user's accounts from DB
pub async fn delete_all(user_id: u64, db: &DatabaseConnection) -> crate::Result<()> {
Self::delete_many()
.filter(Column::UserId.eq(user_id))
.exec(db)
.await?;
Ok(())
}
} }

View File

@ -1,5 +1,5 @@
use crate::{ use crate::{
entity::{account, prelude::*}, entity::prelude::*,
errors::NoUserInfo, errors::NoUserInfo,
handlers::{markups::deletion_markup, utils::package_handler, MainDialogue, State}, handlers::{markups::deletion_markup, utils::package_handler, MainDialogue, State},
}; };
@ -17,10 +17,7 @@ async fn get_master_pass(
) -> crate::Result<()> { ) -> crate::Result<()> {
dialogue.exit().await?; dialogue.exit().await?;
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
Account::delete_many() Account::delete_all(user_id, &db).await?;
.filter(account::Column::UserId.eq(user_id))
.exec(&db)
.await?;
MasterPass::delete_by_id(user_id).exec(&db).await?; MasterPass::delete_by_id(user_id).exec(&db).await?;
bot.send_message(msg.chat.id, "Everything was deleted") bot.send_message(msg.chat.id, "Everything was deleted")
.reply_markup(deletion_markup()) .reply_markup(deletion_markup())