feat(business_profile): add profile id in affected tables and modify api contract (#1971)

This commit is contained in:
Narayan Bhat
2023-08-23 19:34:37 +05:30
committed by GitHub
parent bca9d5013b
commit fe8d4c2eec
29 changed files with 346 additions and 76 deletions

View File

@ -1,9 +1,9 @@
use std::marker::PhantomData;
use api_models::enums::{DisputeStage, DisputeStatus};
use common_utils::errors::CustomResult;
#[cfg(feature = "payouts")]
use common_utils::{crypto::Encryptable, pii::Email};
use common_utils::{errors::CustomResult, ext_traits::AsyncExt};
use error_stack::{IntoReport, ResultExt};
use router_env::{instrument, tracing};
use uuid::Uuid;
@ -16,7 +16,8 @@ use crate::core::payments;
use crate::{
configs::settings,
consts,
core::errors::{self, RouterResult},
core::errors::{self, RouterResult, StorageErrorExt},
db::StorageInterface,
routes::AppState,
types::{
self, domain,
@ -839,3 +840,31 @@ pub fn get_connector_request_reference_id(
payment_attempt.attempt_id.clone()
}
}
/// Validate whether the profile_id exists and is associated with the merchant_id
pub async fn validate_and_get_business_profile(
db: &dyn StorageInterface,
profile_id: Option<&String>,
merchant_id: &str,
) -> RouterResult<Option<storage::business_profile::BusinessProfile>> {
profile_id
.async_map(|profile_id| async {
db.find_business_profile_by_profile_id(profile_id)
.await
.to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound {
id: profile_id.to_owned(),
})
})
.await
.transpose()?
.map(|business_profile| {
// Check if the merchant_id of business profile is same as the current merchant_id
if business_profile.merchant_id.ne(merchant_id) {
Err(errors::ApiErrorResponse::AccessForbidden)
} else {
Ok(business_profile)
}
})
.transpose()
.into_report()
}