feat: Change customer to account_holder to be one-to-many (#11803)
This commit is contained in:
1 parent
6053ec3976
commit
e0109540fa
2 files changed
+20
-7
No files matched your search
+15
-6
@@ -89,7 +89,7 @@ export const createPaymentSessionsWorkflow = createWorkflow(
|
|||||||
return !!data.input.customer_id
|
return !!data.input.customer_id
|
||||||
}
|
}
|
||||||
).then(() => {
|
).then(() => {
|
||||||
const customer: CustomerDTO & { account_holder: AccountHolderDTO } =
|
const customer: CustomerDTO & { account_holders: AccountHolderDTO[] } =
|
||||||
useRemoteQueryStep({
|
useRemoteQueryStep({
|
||||||
entry_point: "customer",
|
entry_point: "customer",
|
||||||
fields: [
|
fields: [
|
||||||
@@ -100,7 +100,7 @@ export const createPaymentSessionsWorkflow = createWorkflow(
|
|||||||
"last_name",
|
"last_name",
|
||||||
"phone",
|
"phone",
|
||||||
"addresses.*",
|
"addresses.*",
|
||||||
"account_holder.*",
|
"account_holders.*",
|
||||||
"metadata",
|
"metadata",
|
||||||
],
|
],
|
||||||
variables: { id: input.customer_id },
|
variables: { id: input.customer_id },
|
||||||
@@ -116,11 +116,17 @@ export const createPaymentSessionsWorkflow = createWorkflow(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const existingAccountHolder = transform({ customer, input }, (data) => {
|
||||||
|
return data.customer.account_holders.find(
|
||||||
|
(ac) => ac.provider_id === data.input.provider_id
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
const accountHolderInput = {
|
const accountHolderInput = {
|
||||||
provider_id: input.provider_id,
|
provider_id: input.provider_id,
|
||||||
context: {
|
context: {
|
||||||
// The module is idempotent, so if there already is a linked account holder, the module will simply return it back.
|
// The module is idempotent, so if there already is a linked account holder, the module will simply return it back.
|
||||||
account_holder: customer.account_holder,
|
account_holder: existingAccountHolder,
|
||||||
customer: paymentCustomer,
|
customer: paymentCustomer,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -131,11 +137,14 @@ export const createPaymentSessionsWorkflow = createWorkflow(
|
|||||||
|
|
||||||
when(
|
when(
|
||||||
"account-holder-created",
|
"account-holder-created",
|
||||||
{ paymentCustomer, accountHolder },
|
{ paymentCustomer, accountHolder, input },
|
||||||
(data) => {
|
(data) => {
|
||||||
return (
|
return (
|
||||||
!isPresent(data.paymentCustomer?.account_holder) &&
|
!isPresent(
|
||||||
isPresent(data.accountHolder)
|
data.paymentCustomer?.account_holders.find(
|
||||||
|
(ac) => ac.provider_id === data.input.provider_id
|
||||||
|
)
|
||||||
|
) && isPresent(data.accountHolder)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
).then(() => {
|
).then(() => {
|
||||||
|
|||||||
@@ -42,13 +42,17 @@ export const CustomerAccountHolder: ModuleJoinerConfig = {
|
|||||||
serviceName: Modules.CUSTOMER,
|
serviceName: Modules.CUSTOMER,
|
||||||
entity: "Customer",
|
entity: "Customer",
|
||||||
fieldAlias: {
|
fieldAlias: {
|
||||||
account_holder: "account_holder_link.account_holder",
|
account_holders: {
|
||||||
|
path: "account_holder_link.account_holder",
|
||||||
|
isList: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
relationship: {
|
relationship: {
|
||||||
serviceName: LINKS.CustomerAccountHolder,
|
serviceName: LINKS.CustomerAccountHolder,
|
||||||
primaryKey: "customer_id",
|
primaryKey: "customer_id",
|
||||||
foreignKey: "id",
|
foreignKey: "id",
|
||||||
alias: "account_holder_link",
|
alias: "account_holder_link",
|
||||||
|
isList: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user