Add endpoint to get sales_person for current user
This commit is contained in:
parent
42ebce15e8
commit
bd887cfd7b
12 changed files with 108 additions and 5 deletions
|
|
@ -125,7 +125,7 @@ where
|
|||
|
||||
async fn get_for_week(
|
||||
&self,
|
||||
calendar_week: i32,
|
||||
calendar_week: u8,
|
||||
year: u32,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<Arc<[Booking]>, ServiceError> {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,18 @@ where
|
|||
{
|
||||
type Context = UserService::Context;
|
||||
|
||||
async fn current_user_id(
|
||||
&self,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<Option<Arc<str>>, ServiceError> {
|
||||
match context {
|
||||
Authentication::Full => Ok(None),
|
||||
Authentication::Context(context) => {
|
||||
let current_user = self.user_service.current_user(context).await?;
|
||||
Ok(Some(current_user))
|
||||
}
|
||||
}
|
||||
}
|
||||
async fn check_permission(
|
||||
&self,
|
||||
privilege: &str,
|
||||
|
|
|
|||
|
|
@ -232,4 +232,38 @@ where
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_sales_person_for_user(
|
||||
&self,
|
||||
user_id: Arc<str>,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<Option<SalesPerson>, ServiceError> {
|
||||
self.permission_service
|
||||
.check_permission("hr", context)
|
||||
.await?;
|
||||
Ok(self
|
||||
.sales_person_dao
|
||||
.find_sales_person_by_user_id(&user_id)
|
||||
.await?
|
||||
.as_ref()
|
||||
.map(SalesPerson::from))
|
||||
}
|
||||
|
||||
async fn get_sales_person_current_user(
|
||||
&self,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<Option<SalesPerson>, ServiceError> {
|
||||
let current_user = if let Some(current_user) = self
|
||||
.permission_service
|
||||
.current_user_id(context.clone())
|
||||
.await?
|
||||
{
|
||||
current_user
|
||||
} else {
|
||||
return Ok(None);
|
||||
};
|
||||
Ok(self
|
||||
.get_sales_person_for_user(current_user, Authentication::Full)
|
||||
.await?)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue