Basic rest implementation for connecting user to sales-person
This commit is contained in:
parent
e3ec694876
commit
bf94ec33de
10 changed files with 181 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use service::ServiceError;
|
||||
|
||||
pub struct PermissionServiceImpl<PermissionDao, UserService>
|
||||
where
|
||||
|
|
@ -75,6 +76,11 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn user_exists(&self, user: &str, context: Self::Context) -> Result<bool, ServiceError> {
|
||||
self.check_permission("hr", context).await?;
|
||||
Ok(self.permission_dao.find_user(user).await.map(|x| x.is_some())?)
|
||||
}
|
||||
|
||||
async fn get_all_users(
|
||||
&self,
|
||||
context: Self::Context,
|
||||
|
|
|
|||
|
|
@ -188,4 +188,36 @@ where
|
|||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_assigned_user(
|
||||
&self,
|
||||
sales_person_id: Uuid,
|
||||
context: Self::Context,
|
||||
) -> Result<Option<Arc<str>>, ServiceError> {
|
||||
self.permission_service
|
||||
.check_permission("hr", context)
|
||||
.await?;
|
||||
Ok(self.sales_person_dao.get_assigned_user(sales_person_id).await?)
|
||||
}
|
||||
|
||||
async fn set_user(
|
||||
&self,
|
||||
sales_person_id: Uuid,
|
||||
user_id: Option<Arc<str>>,
|
||||
context: Self::Context,
|
||||
) -> Result<(), ServiceError> {
|
||||
self.permission_service
|
||||
.check_permission("hr", context)
|
||||
.await?;
|
||||
self.sales_person_dao
|
||||
.discard_assigned_user(sales_person_id)
|
||||
.await?;
|
||||
if let Some(user) = user_id {
|
||||
self.sales_person_dao
|
||||
.assign_to_user(sales_person_id, user.as_ref(), SALES_PERSON_SERVICE_PROCESS)
|
||||
.await?;
|
||||
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue