chore: Function to return user by its public key
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
parent
33b44cb256
commit
033a21f733
1 changed files with 11 additions and 0 deletions
|
@ -28,6 +28,8 @@ pub trait UserTableExt {
|
||||||
async fn users_exists_in_database(&self) -> ApiResult<bool>;
|
async fn users_exists_in_database(&self) -> ApiResult<bool>;
|
||||||
/// Register new user
|
/// Register new user
|
||||||
async fn register_user(&self, public_key: &PublicKey, is_admin: bool) -> ApiResult<()>;
|
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 {
|
impl UserTableExt for DatabaseConnection {
|
||||||
|
@ -57,4 +59,13 @@ impl UserTableExt for DatabaseConnection {
|
||||||
|
|
||||||
Ok(())
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue