mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 13:30:39 +08:00
feat(users): Add preferred_merchant_id column and update user details API (#3373)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -253,6 +253,7 @@ pub async fn change_password(
|
||||
name: None,
|
||||
password: Some(new_password_hash),
|
||||
is_verified: None,
|
||||
preferred_merchant_id: None,
|
||||
},
|
||||
)
|
||||
.await
|
||||
@ -330,6 +331,7 @@ pub async fn reset_password(
|
||||
name: None,
|
||||
password: Some(hash_password),
|
||||
is_verified: Some(true),
|
||||
preferred_merchant_id: None,
|
||||
},
|
||||
)
|
||||
.await
|
||||
@ -786,3 +788,47 @@ pub async fn verify_token(
|
||||
user_email: user.email,
|
||||
}))
|
||||
}
|
||||
|
||||
pub async fn update_user_details(
|
||||
state: AppState,
|
||||
user_token: auth::UserFromToken,
|
||||
req: user_api::UpdateUserAccountDetailsRequest,
|
||||
) -> UserResponse<()> {
|
||||
let user: domain::UserFromStorage = state
|
||||
.store
|
||||
.find_user_by_id(&user_token.user_id)
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)?
|
||||
.into();
|
||||
|
||||
let name = req.name.map(domain::UserName::new).transpose()?;
|
||||
|
||||
if let Some(ref preferred_merchant_id) = req.preferred_merchant_id {
|
||||
let _ = state
|
||||
.store
|
||||
.find_user_role_by_user_id_merchant_id(user.get_user_id(), preferred_merchant_id)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
if e.current_context().is_db_not_found() {
|
||||
e.change_context(UserErrors::MerchantIdNotFound)
|
||||
} else {
|
||||
e.change_context(UserErrors::InternalServerError)
|
||||
}
|
||||
})?;
|
||||
}
|
||||
|
||||
let user_update = storage_user::UserUpdate::AccountUpdate {
|
||||
name: name.map(|x| x.get_secret().expose()),
|
||||
password: None,
|
||||
is_verified: None,
|
||||
preferred_merchant_id: req.preferred_merchant_id,
|
||||
};
|
||||
|
||||
state
|
||||
.store
|
||||
.update_user_by_user_id(user.get_user_id(), user_update)
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)?;
|
||||
|
||||
Ok(ApplicationResponse::StatusOk)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user