mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	feat: rename columns in organization for v2 (#5424)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
		| @ -12,6 +12,8 @@ use common_utils::{ | ||||
|     types::keymanager::{self as km_types, KeyManagerState}, | ||||
| }; | ||||
| use diesel_models::configs; | ||||
| #[cfg(all(any(feature = "v1", feature = "v2"), feature = "olap"))] | ||||
| use diesel_models::organization::OrganizationBridge; | ||||
| use error_stack::{report, FutureExt, ResultExt}; | ||||
| use futures::future::try_join_all; | ||||
| use masking::{ExposeInterface, PeekInterface, Secret}; | ||||
| @ -134,7 +136,7 @@ pub async fn update_organization( | ||||
|     req: api::OrganizationRequest, | ||||
| ) -> RouterResponse<api::OrganizationResponse> { | ||||
|     let organization_update = diesel_models::organization::OrganizationUpdate::Update { | ||||
|         org_name: req.organization_name, | ||||
|         organization_name: req.organization_name, | ||||
|         organization_details: req.organization_details, | ||||
|         metadata: req.metadata, | ||||
|     }; | ||||
| @ -387,7 +389,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate { | ||||
|                     payout_routing_algorithm: self.payout_routing_algorithm, | ||||
|                     #[cfg(not(feature = "payouts"))] | ||||
|                     payout_routing_algorithm: None, | ||||
|                     organization_id: organization.org_id, | ||||
|                     organization_id: organization.get_organization_id(), | ||||
|                     is_recon_enabled: false, | ||||
|                     default_profile: None, | ||||
|                     recon_status: diesel_models::enums::ReconStatus::NotRequested, | ||||
| @ -638,7 +640,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate { | ||||
|             }, | ||||
|         )?; | ||||
|  | ||||
|         CreateOrValidateOrganization::new(self.organization_id.clone()) | ||||
|         let organization = CreateOrValidateOrganization::new(self.organization_id.clone()) | ||||
|             .create_or_validate(db) | ||||
|             .await?; | ||||
|  | ||||
| @ -692,7 +694,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate { | ||||
|                     intent_fulfillment_time: None, | ||||
|                     frm_routing_algorithm: None, | ||||
|                     payout_routing_algorithm: None, | ||||
|                     organization_id: self.organization_id, | ||||
|                     organization_id: organization.get_organization_id(), | ||||
|                     is_recon_enabled: false, | ||||
|                     default_profile: None, | ||||
|                     recon_status: diesel_models::enums::ReconStatus::NotRequested, | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| use common_utils::{errors::CustomResult, id_type}; | ||||
| use diesel_models::organization as storage; | ||||
| use diesel_models::{organization as storage, organization::OrganizationBridge}; | ||||
| use error_stack::report; | ||||
| use router_env::{instrument, tracing}; | ||||
|  | ||||
| @ -73,21 +73,14 @@ impl OrganizationInterface for super::MockDb { | ||||
|  | ||||
|         if organizations | ||||
|             .iter() | ||||
|             .any(|org| org.org_id == organization.org_id) | ||||
|             .any(|org| org.get_organization_id() == organization.get_organization_id()) | ||||
|         { | ||||
|             Err(errors::StorageError::DuplicateValue { | ||||
|                 entity: "org_id", | ||||
|                 key: None, | ||||
|             })? | ||||
|         } | ||||
|         let org = storage::Organization { | ||||
|             org_id: organization.org_id.clone(), | ||||
|             org_name: organization.org_name, | ||||
|             organization_details: organization.organization_details, | ||||
|             metadata: organization.metadata, | ||||
|             created_at: common_utils::date_time::now(), | ||||
|             modified_at: common_utils::date_time::now(), | ||||
|         }; | ||||
|         let org = storage::Organization::new(organization); | ||||
|         organizations.push(org.clone()); | ||||
|         Ok(org) | ||||
|     } | ||||
| @ -100,7 +93,7 @@ impl OrganizationInterface for super::MockDb { | ||||
|  | ||||
|         organizations | ||||
|             .iter() | ||||
|             .find(|org| org.org_id == *org_id) | ||||
|             .find(|org| org.get_organization_id() == *org_id) | ||||
|             .cloned() | ||||
|             .ok_or( | ||||
|                 errors::StorageError::ValueNotFound(format!( | ||||
| @ -120,18 +113,20 @@ impl OrganizationInterface for super::MockDb { | ||||
|  | ||||
|         organizations | ||||
|             .iter_mut() | ||||
|             .find(|org| org.org_id == *org_id) | ||||
|             .find(|org| org.get_organization_id() == *org_id) | ||||
|             .map(|org| match &update { | ||||
|                 storage::OrganizationUpdate::Update { | ||||
|                     org_name, | ||||
|                     organization_name, | ||||
|                     organization_details, | ||||
|                     metadata, | ||||
|                 } => storage::Organization { | ||||
|                     org_name: org_name.clone(), | ||||
|                     organization_details: organization_details.clone(), | ||||
|                     metadata: metadata.clone(), | ||||
|                     ..org.to_owned() | ||||
|                 }, | ||||
|                 } => { | ||||
|                     organization_name | ||||
|                         .as_ref() | ||||
|                         .map(|org_name| org.set_organization_name(org_name.to_owned())); | ||||
|                     organization_details.clone_into(&mut org.organization_details); | ||||
|                     metadata.clone_into(&mut org.metadata); | ||||
|                     org | ||||
|                 } | ||||
|             }) | ||||
|             .ok_or( | ||||
|                 errors::StorageError::ValueNotFound(format!( | ||||
| @ -140,5 +135,6 @@ impl OrganizationInterface for super::MockDb { | ||||
|                 )) | ||||
|                 .into(), | ||||
|             ) | ||||
|             .cloned() | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -15,6 +15,7 @@ use common_utils::{ | ||||
|     ext_traits::{AsyncExt, Encode, ValueExt}, | ||||
|     types::keymanager::Identifier, | ||||
| }; | ||||
| use diesel_models::organization::OrganizationBridge; | ||||
| use error_stack::{report, ResultExt}; | ||||
| use hyperswitch_domain_models::{ | ||||
|     merchant_key_store::MerchantKeyStore, type_encryption::decrypt_optional, | ||||
| @ -30,8 +31,8 @@ use crate::{ | ||||
| impl ForeignFrom<diesel_models::organization::Organization> for OrganizationResponse { | ||||
|     fn foreign_from(org: diesel_models::organization::Organization) -> Self { | ||||
|         Self { | ||||
|             organization_id: org.org_id, | ||||
|             organization_name: org.org_name, | ||||
|             organization_id: org.get_organization_id(), | ||||
|             organization_name: org.get_organization_name(), | ||||
|             organization_details: org.organization_details, | ||||
|             metadata: org.metadata, | ||||
|             modified_at: org.modified_at, | ||||
|  | ||||
| @ -10,7 +10,7 @@ use common_utils::{ | ||||
| }; | ||||
| use diesel_models::{ | ||||
|     enums::{TotpStatus, UserRoleVersion, UserStatus}, | ||||
|     organization::{self as diesel_org, Organization}, | ||||
|     organization::{self as diesel_org, Organization, OrganizationBridge}, | ||||
|     user as storage_user, | ||||
|     user_role::{UserRole, UserRoleNew}, | ||||
| }; | ||||
| @ -254,7 +254,7 @@ impl NewUserOrganization { | ||||
|     } | ||||
|  | ||||
|     pub fn get_organization_id(&self) -> id_type::OrganizationId { | ||||
|         self.0.org_id.clone() | ||||
|         self.0.get_organization_id() | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -300,14 +300,10 @@ impl From<(user_api::CreateInternalUserRequest, id_type::OrganizationId)> for Ne | ||||
|  | ||||
| impl From<UserMerchantCreateRequestWithToken> for NewUserOrganization { | ||||
|     fn from(value: UserMerchantCreateRequestWithToken) -> Self { | ||||
|         Self(diesel_org::OrganizationNew { | ||||
|             org_id: value.2.org_id, | ||||
|             org_name: Some(value.1.company_name), | ||||
|             organization_details: None, | ||||
|             metadata: None, | ||||
|             created_at: common_utils::date_time::now(), | ||||
|             modified_at: common_utils::date_time::now(), | ||||
|         }) | ||||
|         Self(diesel_org::OrganizationNew::new( | ||||
|             value.2.org_id, | ||||
|             Some(value.1.company_name), | ||||
|         )) | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -1389,14 +1389,7 @@ impl ForeignFrom<api_models::organization::OrganizationNew> | ||||
|     for diesel_models::organization::OrganizationNew | ||||
| { | ||||
|     fn foreign_from(item: api_models::organization::OrganizationNew) -> Self { | ||||
|         Self { | ||||
|             org_id: item.org_id, | ||||
|             org_name: item.org_name, | ||||
|             organization_details: None, | ||||
|             metadata: None, | ||||
|             created_at: common_utils::date_time::now(), | ||||
|             modified_at: common_utils::date_time::now(), | ||||
|         } | ||||
|         Self::new(item.org_id, item.org_name) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -1405,14 +1398,15 @@ impl ForeignFrom<api_models::organization::OrganizationRequest> | ||||
| { | ||||
|     fn foreign_from(item: api_models::organization::OrganizationRequest) -> Self { | ||||
|         let org_new = api_models::organization::OrganizationNew::new(None); | ||||
|         Self { | ||||
|             org_id: org_new.org_id, | ||||
|             org_name: item.organization_name, | ||||
|             organization_details: item.organization_details, | ||||
|             metadata: item.metadata, | ||||
|             created_at: common_utils::date_time::now(), | ||||
|             modified_at: common_utils::date_time::now(), | ||||
|         } | ||||
|         let api_models::organization::OrganizationRequest { | ||||
|             organization_name, | ||||
|             organization_details, | ||||
|             metadata, | ||||
|         } = item; | ||||
|         let mut org_new_db = Self::new(org_new.org_id, organization_name); | ||||
|         org_new_db.organization_details = organization_details; | ||||
|         org_new_db.metadata = metadata; | ||||
|         org_new_db | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Hrithikesh
					Hrithikesh