update when-then blocks across docs
This commit is contained in:
@@ -529,12 +529,15 @@ In the workflow, you retrieve the cart's linked `Custom` record using Query.
|
||||
Next, replace the `TODO` with the following:
|
||||
|
||||
```ts title="src/workflows/update-custom-from-cart/index.ts"
|
||||
const created = when({
|
||||
input,
|
||||
carts,
|
||||
}, (data) =>
|
||||
!data.carts[0].custom &&
|
||||
data.input.additional_data?.custom_name?.length > 0
|
||||
const created = when(
|
||||
"create-cart-custom-link",
|
||||
{
|
||||
input,
|
||||
carts,
|
||||
},
|
||||
(data) =>
|
||||
!data.carts[0].custom &&
|
||||
data.input.additional_data?.custom_name?.length > 0
|
||||
)
|
||||
.then(() => {
|
||||
const custom = createCustomStep({
|
||||
@@ -563,14 +566,16 @@ To create the `Custom` record, you use the `createCustomStep` you created in an
|
||||
Next, replace the new `TODO` with the following:
|
||||
|
||||
```ts title="src/workflows/update-custom-from-cart/index.ts"
|
||||
const deleted = when({
|
||||
input,
|
||||
carts,
|
||||
}, (data) =>
|
||||
data.carts[0].custom && (
|
||||
data.input.additional_data?.custom_name === null ||
|
||||
data.input.additional_data?.custom_name.length === 0
|
||||
)
|
||||
const deleted = when(
|
||||
"delete-cart-custom-link"
|
||||
{
|
||||
input,
|
||||
carts,
|
||||
}, (data) =>
|
||||
data.carts[0].custom && (
|
||||
data.input.additional_data?.custom_name === null ||
|
||||
data.input.additional_data?.custom_name.length === 0
|
||||
)
|
||||
)
|
||||
.then(() => {
|
||||
deleteCustomStep({
|
||||
@@ -599,12 +604,10 @@ const updated = when({
|
||||
carts,
|
||||
}, (data) => data.carts[0].custom && data.input.additional_data?.custom_name?.length > 0)
|
||||
.then(() => {
|
||||
const custom = updateCustomStep({
|
||||
return updateCustomStep({
|
||||
id: carts[0].custom.id,
|
||||
custom_name: input.additional_data.custom_name,
|
||||
})
|
||||
|
||||
return custom
|
||||
})
|
||||
|
||||
return new WorkflowResponse({
|
||||
|
||||
@@ -541,12 +541,14 @@ In the workflow, you retrieve the customer's linked `Custom` record using Query.
|
||||
Next, replace the `TODO` with the following:
|
||||
|
||||
```ts title="src/workflows/update-custom-from-customer/index.ts"
|
||||
const created = when({
|
||||
input,
|
||||
customers,
|
||||
}, (data) =>
|
||||
!data.customers[0].custom &&
|
||||
data.input.additional_data?.custom_name?.length > 0
|
||||
const created = when(
|
||||
"create-customer-custom-link"
|
||||
{
|
||||
input,
|
||||
customers,
|
||||
}, (data) =>
|
||||
!data.customers[0].custom &&
|
||||
data.input.additional_data?.custom_name?.length > 0
|
||||
)
|
||||
.then(() => {
|
||||
const custom = createCustomStep({
|
||||
@@ -575,14 +577,16 @@ To create the `Custom` record, you use the `createCustomStep` you created in an
|
||||
Next, replace the new `TODO` with the following:
|
||||
|
||||
```ts title="src/workflows/update-custom-from-customer/index.ts"
|
||||
const deleted = when({
|
||||
input,
|
||||
customers,
|
||||
}, (data) =>
|
||||
data.customers[0].custom && (
|
||||
data.input.additional_data?.custom_name === null ||
|
||||
data.input.additional_data?.custom_name.length === 0
|
||||
)
|
||||
const deleted = when(
|
||||
"delete-customer-custom-link",
|
||||
{
|
||||
input,
|
||||
customers,
|
||||
}, (data) =>
|
||||
data.customers[0].custom && (
|
||||
data.input.additional_data?.custom_name === null ||
|
||||
data.input.additional_data?.custom_name.length === 0
|
||||
)
|
||||
)
|
||||
.then(() => {
|
||||
deleteCustomStep({
|
||||
@@ -611,12 +615,10 @@ const updated = when({
|
||||
customers,
|
||||
}, (data) => data.customers[0].custom && data.input.additional_data?.custom_name?.length > 0)
|
||||
.then(() => {
|
||||
const custom = updateCustomStep({
|
||||
return updateCustomStep({
|
||||
id: customers[0].custom.id,
|
||||
custom_name: input.additional_data.custom_name,
|
||||
})
|
||||
|
||||
return custom
|
||||
})
|
||||
|
||||
return new WorkflowResponse({
|
||||
|
||||
@@ -547,12 +547,14 @@ In the workflow, you retrieve the product's linked `Custom` record using Query.
|
||||
Next, replace the `TODO` with the following:
|
||||
|
||||
```ts title="src/workflows/update-custom-from-product/index.ts"
|
||||
const created = when({
|
||||
input,
|
||||
products,
|
||||
}, (data) =>
|
||||
!data.products[0].custom &&
|
||||
data.input.additional_data?.custom_name?.length > 0
|
||||
const created = when(
|
||||
"create-product-custom-link",
|
||||
{
|
||||
input,
|
||||
products,
|
||||
}, (data) =>
|
||||
!data.products[0].custom &&
|
||||
data.input.additional_data?.custom_name?.length > 0
|
||||
)
|
||||
.then(() => {
|
||||
const custom = createCustomStep({
|
||||
@@ -581,14 +583,16 @@ To create the `Custom` record, you use the `createCustomStep` you created in an
|
||||
Next, replace the new `TODO` with the following:
|
||||
|
||||
```ts title="src/workflows/update-custom-from-product/index.ts"
|
||||
const deleted = when({
|
||||
input,
|
||||
products,
|
||||
}, (data) =>
|
||||
data.products[0].custom && (
|
||||
data.input.additional_data?.custom_name === null ||
|
||||
data.input.additional_data?.custom_name.length === 0
|
||||
)
|
||||
const deleted = when(
|
||||
"delete-product-custom-link",
|
||||
{
|
||||
input,
|
||||
products,
|
||||
}, (data) =>
|
||||
data.products[0].custom && (
|
||||
data.input.additional_data?.custom_name === null ||
|
||||
data.input.additional_data?.custom_name.length === 0
|
||||
)
|
||||
)
|
||||
.then(() => {
|
||||
deleteCustomStep({
|
||||
@@ -617,12 +621,10 @@ const updated = when({
|
||||
products,
|
||||
}, (data) => data.products[0].custom && data.input.additional_data?.custom_name?.length > 0)
|
||||
.then(() => {
|
||||
const custom = updateCustomStep({
|
||||
return updateCustomStep({
|
||||
id: products[0].custom.id,
|
||||
custom_name: input.additional_data.custom_name,
|
||||
})
|
||||
|
||||
return custom
|
||||
})
|
||||
|
||||
return new WorkflowResponse({
|
||||
|
||||
@@ -553,12 +553,14 @@ In the workflow, you retrieve the promotion's linked `Custom` record using Query
|
||||
Next, replace the `TODO` with the following:
|
||||
|
||||
```ts title="src/workflows/update-custom-from-promotion/index.ts"
|
||||
const created = when({
|
||||
input,
|
||||
promotions,
|
||||
}, (data) =>
|
||||
!data.promotions[0].custom &&
|
||||
data.input.additional_data?.custom_name?.length > 0
|
||||
const created = when(
|
||||
"create-promotion-custom-link",
|
||||
{
|
||||
input,
|
||||
promotions,
|
||||
}, (data) =>
|
||||
!data.promotions[0].custom &&
|
||||
data.input.additional_data?.custom_name?.length > 0
|
||||
)
|
||||
.then(() => {
|
||||
const custom = createCustomStep({
|
||||
@@ -587,14 +589,16 @@ To create the `Custom` record, you use the `createCustomStep` you created in an
|
||||
Next, replace the new `TODO` with the following:
|
||||
|
||||
```ts title="src/workflows/update-custom-from-promotion/index.ts"
|
||||
const deleted = when({
|
||||
input,
|
||||
promotions,
|
||||
}, (data) =>
|
||||
data.promotions[0].custom && (
|
||||
data.input.additional_data?.custom_name === null ||
|
||||
data.input.additional_data?.custom_name.length === 0
|
||||
)
|
||||
const deleted = when(
|
||||
"delete-promotion-custom-link",
|
||||
{
|
||||
input,
|
||||
promotions,
|
||||
}, (data) =>
|
||||
data.promotions[0].custom && (
|
||||
data.input.additional_data?.custom_name === null ||
|
||||
data.input.additional_data?.custom_name.length === 0
|
||||
)
|
||||
)
|
||||
.then(() => {
|
||||
deleteCustomStep({
|
||||
@@ -623,12 +627,10 @@ const updated = when({
|
||||
promotions,
|
||||
}, (data) => data.promotions[0].custom && data.input.additional_data?.custom_name?.length > 0)
|
||||
.then(() => {
|
||||
const custom = updateCustomStep({
|
||||
return updateCustomStep({
|
||||
id: promotions[0].custom.id,
|
||||
custom_name: input.additional_data.custom_name,
|
||||
})
|
||||
|
||||
return custom
|
||||
})
|
||||
|
||||
return new WorkflowResponse({
|
||||
|
||||
Reference in New Issue
Block a user