Implemented account altering

This commit is contained in:
2023-08-04 00:23:02 +03:00
parent ab62e74cb7
commit 386f060a41
10 changed files with 185 additions and 13 deletions

View File

@ -1,7 +1,7 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
use futures::Stream;
use sea_orm::{entity::prelude::*, QueryOrder, QuerySelect, Statement};
use sea_orm::{entity::prelude::*, ActiveValue::Set, QueryOrder, QuerySelect, Statement};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "account")]
@ -88,6 +88,7 @@ impl Entity {
}
/// Gets a name by a hex of a SHA256 hash of the name
#[inline]
pub async fn get_name_by_hash(
user_id: u64,
hash: String,
@ -102,4 +103,38 @@ impl Entity {
.map(|result| result.try_get_by_index(0))
.transpose()
}
#[inline]
pub async fn get_salt(
user_id: u64,
name: String,
db: &DatabaseConnection,
) -> crate::Result<Option<Vec<u8>>> {
Self::find_by_id((user_id, name))
.select_only()
.column(Column::Salt)
.into_tuple()
.one(db)
.await
}
#[inline]
pub async fn update_name(
user_id: u64,
original_name: String,
new_name: String,
db: &DatabaseConnection,
) -> crate::Result<()> {
Self::update_many()
.set(ActiveModel {
name: Set(new_name),
..Default::default()
})
.filter(Column::UserId.eq(user_id))
.filter(Column::Name.eq(original_name))
.exec(db)
.await?;
Ok(())
}
}