fix(merchant_account): change primary_business_details to vec in update (#877)

This commit is contained in:
Narayan Bhat
2023-04-14 12:40:46 +05:30
committed by GitHub
parent 5e9d7d6b53
commit 396d24fe05
2 changed files with 19 additions and 12 deletions

View File

@ -134,7 +134,7 @@ pub struct MerchantAccountUpdate {
pub locker_id: Option<String>, pub locker_id: Option<String>,
///Default business details for connector routing ///Default business details for connector routing
pub primary_business_details: Option<PrimaryBusinessDetails>, pub primary_business_details: Option<Vec<PrimaryBusinessDetails>>,
} }
#[derive(Clone, Debug, ToSchema, Serialize)] #[derive(Clone, Debug, ToSchema, Serialize)]

View File

@ -89,11 +89,12 @@ pub async fn create_merchant_account(
.attach_printable("Unexpected create API key response"), .attach_printable("Unexpected create API key response"),
}?; }?;
let primary_business_details = let primary_business_details = utils::Encode::<Vec<PrimaryBusinessDetails>>::encode_to_value(
utils::Encode::<api::WebhookDetails>::encode_to_value(&get_primary_business_details(&req)) &get_primary_business_details(&req),
.change_context(errors::ApiErrorResponse::InvalidDataValue { )
field_name: "primary_business_details", .change_context(errors::ApiErrorResponse::InvalidDataValue {
})?; field_name: "primary_business_details",
})?;
let merchant_details = let merchant_details =
req.merchant_details req.merchant_details
@ -214,6 +215,17 @@ pub async fn merchant_account_update(
.attach_printable("Invalid routing algorithm given")?; .attach_printable("Invalid routing algorithm given")?;
} }
let primary_business_details = req
.primary_business_details
.as_ref()
.map(|primary_business_details| {
utils::Encode::<Vec<PrimaryBusinessDetails>>::encode_to_value(primary_business_details)
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "primary_business_details",
})
})
.transpose()?;
let updated_merchant_account = storage::MerchantAccountUpdate::Update { let updated_merchant_account = storage::MerchantAccountUpdate::Update {
merchant_name: req.merchant_name, merchant_name: req.merchant_name,
@ -248,12 +260,7 @@ pub async fn merchant_account_update(
locker_id: req.locker_id, locker_id: req.locker_id,
metadata: req.metadata, metadata: req.metadata,
publishable_key: None, publishable_key: None,
primary_business_details: req primary_business_details,
.primary_business_details
.as_ref()
.map(utils::Encode::<PrimaryBusinessDetails>::encode_to_value)
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)?,
}; };
let response = db let response = db