feat(user): add user_list and switch_list apis (#3033)

Co-authored-by: Mani Chandra Dulam <mani.dchandra@juspay.in>
This commit is contained in:
Apoorv Dixit
2023-12-01 19:07:17 +05:30
committed by GitHub
parent 95876b0ce0
commit ec15ddd0d0
16 changed files with 356 additions and 52 deletions

View File

@ -324,3 +324,29 @@ pub async fn create_merchant_account(
Ok(ApplicationResponse::StatusOk)
}
pub async fn list_merchant_ids_for_user(
state: AppState,
user: auth::UserFromToken,
) -> UserResponse<Vec<String>> {
Ok(ApplicationResponse::Json(
utils::user::get_merchant_ids_for_user(state, &user.user_id).await?,
))
}
pub async fn get_users_for_merchant_account(
state: AppState,
user_from_token: auth::UserFromToken,
) -> UserResponse<user_api::GetUsersResponse> {
let users = state
.store
.find_users_and_roles_by_merchant_id(user_from_token.merchant_id.as_str())
.await
.change_context(UserErrors::InternalServerError)
.attach_printable("No users for given merchant id")?
.into_iter()
.filter_map(|(user, role)| domain::UserAndRoleJoined(user, role).try_into().ok())
.collect();
Ok(ApplicationResponse::Json(user_api::GetUsersResponse(users)))
}