chore: Function to return user by its public key

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-07-10 20:16:55 +03:00
parent 33b44cb256
commit 033a21f733
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F

View file

@ -28,6 +28,8 @@ pub trait UserTableExt {
async fn users_exists_in_database(&self) -> ApiResult<bool>;
/// Register new user
async fn register_user(&self, public_key: &PublicKey, is_admin: bool) -> ApiResult<()>;
/// Returns user by its public key
async fn get_user_by_pubk(&self, public_key: &PublicKey) -> ApiResult<Option<UserModel>>;
}
impl UserTableExt for DatabaseConnection {
@ -57,4 +59,13 @@ impl UserTableExt for DatabaseConnection {
Ok(())
}
#[logcall]
async fn get_user_by_pubk(&self, public_key: &PublicKey) -> ApiResult<Option<UserModel>> {
UserEntity::find()
.filter(UserColumn::PublicKey.eq(public_key.to_string()))
.one(self)
.await
.map_err(ApiError::SeaOrm)
}
}