update when-then blocks across docs

This commit is contained in:
Shahed Nasser
2024-12-11 11:08:52 +02:00
parent fd23f13cfd
commit 3522c0f0e0
6 changed files with 83 additions and 75 deletions
@@ -529,12 +529,15 @@ In the workflow, you retrieve the cart's linked `Custom` record using Query.
Next, replace the `TODO` with the following: Next, replace the `TODO` with the following:
```ts title="src/workflows/update-custom-from-cart/index.ts" ```ts title="src/workflows/update-custom-from-cart/index.ts"
const created = when({ const created = when(
input, "create-cart-custom-link",
carts, {
}, (data) => input,
!data.carts[0].custom && carts,
data.input.additional_data?.custom_name?.length > 0 },
(data) =>
!data.carts[0].custom &&
data.input.additional_data?.custom_name?.length > 0
) )
.then(() => { .then(() => {
const custom = createCustomStep({ 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: Next, replace the new `TODO` with the following:
```ts title="src/workflows/update-custom-from-cart/index.ts" ```ts title="src/workflows/update-custom-from-cart/index.ts"
const deleted = when({ const deleted = when(
input, "delete-cart-custom-link"
carts, {
}, (data) => input,
data.carts[0].custom && ( carts,
data.input.additional_data?.custom_name === null || }, (data) =>
data.input.additional_data?.custom_name.length === 0 data.carts[0].custom && (
) data.input.additional_data?.custom_name === null ||
data.input.additional_data?.custom_name.length === 0
)
) )
.then(() => { .then(() => {
deleteCustomStep({ deleteCustomStep({
@@ -599,12 +604,10 @@ const updated = when({
carts, carts,
}, (data) => data.carts[0].custom && data.input.additional_data?.custom_name?.length > 0) }, (data) => data.carts[0].custom && data.input.additional_data?.custom_name?.length > 0)
.then(() => { .then(() => {
const custom = updateCustomStep({ return updateCustomStep({
id: carts[0].custom.id, id: carts[0].custom.id,
custom_name: input.additional_data.custom_name, custom_name: input.additional_data.custom_name,
}) })
return custom
}) })
return new WorkflowResponse({ 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: Next, replace the `TODO` with the following:
```ts title="src/workflows/update-custom-from-customer/index.ts" ```ts title="src/workflows/update-custom-from-customer/index.ts"
const created = when({ const created = when(
input, "create-customer-custom-link"
customers, {
}, (data) => input,
!data.customers[0].custom && customers,
data.input.additional_data?.custom_name?.length > 0 }, (data) =>
!data.customers[0].custom &&
data.input.additional_data?.custom_name?.length > 0
) )
.then(() => { .then(() => {
const custom = createCustomStep({ 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: Next, replace the new `TODO` with the following:
```ts title="src/workflows/update-custom-from-customer/index.ts" ```ts title="src/workflows/update-custom-from-customer/index.ts"
const deleted = when({ const deleted = when(
input, "delete-customer-custom-link",
customers, {
}, (data) => input,
data.customers[0].custom && ( customers,
data.input.additional_data?.custom_name === null || }, (data) =>
data.input.additional_data?.custom_name.length === 0 data.customers[0].custom && (
) data.input.additional_data?.custom_name === null ||
data.input.additional_data?.custom_name.length === 0
)
) )
.then(() => { .then(() => {
deleteCustomStep({ deleteCustomStep({
@@ -611,12 +615,10 @@ const updated = when({
customers, customers,
}, (data) => data.customers[0].custom && data.input.additional_data?.custom_name?.length > 0) }, (data) => data.customers[0].custom && data.input.additional_data?.custom_name?.length > 0)
.then(() => { .then(() => {
const custom = updateCustomStep({ return updateCustomStep({
id: customers[0].custom.id, id: customers[0].custom.id,
custom_name: input.additional_data.custom_name, custom_name: input.additional_data.custom_name,
}) })
return custom
}) })
return new WorkflowResponse({ 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: Next, replace the `TODO` with the following:
```ts title="src/workflows/update-custom-from-product/index.ts" ```ts title="src/workflows/update-custom-from-product/index.ts"
const created = when({ const created = when(
input, "create-product-custom-link",
products, {
}, (data) => input,
!data.products[0].custom && products,
data.input.additional_data?.custom_name?.length > 0 }, (data) =>
!data.products[0].custom &&
data.input.additional_data?.custom_name?.length > 0
) )
.then(() => { .then(() => {
const custom = createCustomStep({ 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: Next, replace the new `TODO` with the following:
```ts title="src/workflows/update-custom-from-product/index.ts" ```ts title="src/workflows/update-custom-from-product/index.ts"
const deleted = when({ const deleted = when(
input, "delete-product-custom-link",
products, {
}, (data) => input,
data.products[0].custom && ( products,
data.input.additional_data?.custom_name === null || }, (data) =>
data.input.additional_data?.custom_name.length === 0 data.products[0].custom && (
) data.input.additional_data?.custom_name === null ||
data.input.additional_data?.custom_name.length === 0
)
) )
.then(() => { .then(() => {
deleteCustomStep({ deleteCustomStep({
@@ -617,12 +621,10 @@ const updated = when({
products, products,
}, (data) => data.products[0].custom && data.input.additional_data?.custom_name?.length > 0) }, (data) => data.products[0].custom && data.input.additional_data?.custom_name?.length > 0)
.then(() => { .then(() => {
const custom = updateCustomStep({ return updateCustomStep({
id: products[0].custom.id, id: products[0].custom.id,
custom_name: input.additional_data.custom_name, custom_name: input.additional_data.custom_name,
}) })
return custom
}) })
return new WorkflowResponse({ 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: Next, replace the `TODO` with the following:
```ts title="src/workflows/update-custom-from-promotion/index.ts" ```ts title="src/workflows/update-custom-from-promotion/index.ts"
const created = when({ const created = when(
input, "create-promotion-custom-link",
promotions, {
}, (data) => input,
!data.promotions[0].custom && promotions,
data.input.additional_data?.custom_name?.length > 0 }, (data) =>
!data.promotions[0].custom &&
data.input.additional_data?.custom_name?.length > 0
) )
.then(() => { .then(() => {
const custom = createCustomStep({ 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: Next, replace the new `TODO` with the following:
```ts title="src/workflows/update-custom-from-promotion/index.ts" ```ts title="src/workflows/update-custom-from-promotion/index.ts"
const deleted = when({ const deleted = when(
input, "delete-promotion-custom-link",
promotions, {
}, (data) => input,
data.promotions[0].custom && ( promotions,
data.input.additional_data?.custom_name === null || }, (data) =>
data.input.additional_data?.custom_name.length === 0 data.promotions[0].custom && (
) data.input.additional_data?.custom_name === null ||
data.input.additional_data?.custom_name.length === 0
)
) )
.then(() => { .then(() => {
deleteCustomStep({ deleteCustomStep({
@@ -623,12 +627,10 @@ const updated = when({
promotions, promotions,
}, (data) => data.promotions[0].custom && data.input.additional_data?.custom_name?.length > 0) }, (data) => data.promotions[0].custom && data.input.additional_data?.custom_name?.length > 0)
.then(() => { .then(() => {
const custom = updateCustomStep({ return updateCustomStep({
id: promotions[0].custom.id, id: promotions[0].custom.id,
custom_name: input.additional_data.custom_name, custom_name: input.additional_data.custom_name,
}) })
return custom
}) })
return new WorkflowResponse({ return new WorkflowResponse({
+1 -2
View File
@@ -2296,8 +2296,7 @@ const workflow = createWorkflow(
return input.is_active return input.is_active
} }
).then(() => { ).then(() => {
const stepResult = isActiveStep() return isActiveStep()
return stepResult
}) })
// executed without condition // executed without condition
+5 -5
View File
@@ -2180,15 +2180,15 @@ export const generatedEditDates = {
"app/commerce-modules/auth/reset-password/page.mdx": "2024-11-27T13:33:55.940Z", "app/commerce-modules/auth/reset-password/page.mdx": "2024-11-27T13:33:55.940Z",
"app/storefront-development/customers/reset-password/page.mdx": "2024-09-25T10:21:46.647Z", "app/storefront-development/customers/reset-password/page.mdx": "2024-09-25T10:21:46.647Z",
"app/commerce-modules/api-key/links-to-other-modules/page.mdx": "2024-10-08T08:05:36.596Z", "app/commerce-modules/api-key/links-to-other-modules/page.mdx": "2024-10-08T08:05:36.596Z",
"app/commerce-modules/cart/extend/page.mdx": "2024-12-09T16:11:39.857Z", "app/commerce-modules/cart/extend/page.mdx": "2024-12-11T09:05:37.041Z",
"app/commerce-modules/cart/links-to-other-modules/page.mdx": "2024-10-08T08:22:35.190Z", "app/commerce-modules/cart/links-to-other-modules/page.mdx": "2024-10-08T08:22:35.190Z",
"app/commerce-modules/customer/extend/page.mdx": "2024-12-09T16:15:01.163Z", "app/commerce-modules/customer/extend/page.mdx": "2024-12-11T09:05:35.368Z",
"app/commerce-modules/fulfillment/links-to-other-modules/page.mdx": "2024-10-08T14:58:24.935Z", "app/commerce-modules/fulfillment/links-to-other-modules/page.mdx": "2024-10-08T14:58:24.935Z",
"app/commerce-modules/inventory/links-to-other-modules/page.mdx": "2024-10-08T15:18:30.109Z", "app/commerce-modules/inventory/links-to-other-modules/page.mdx": "2024-10-08T15:18:30.109Z",
"app/commerce-modules/pricing/links-to-other-modules/page.mdx": "2024-10-09T13:51:49.986Z", "app/commerce-modules/pricing/links-to-other-modules/page.mdx": "2024-10-09T13:51:49.986Z",
"app/commerce-modules/product/extend/page.mdx": "2024-12-09T16:15:01.163Z", "app/commerce-modules/product/extend/page.mdx": "2024-12-11T09:07:25.252Z",
"app/commerce-modules/product/links-to-other-modules/page.mdx": "2024-10-09T14:14:09.401Z", "app/commerce-modules/product/links-to-other-modules/page.mdx": "2024-10-09T14:14:09.401Z",
"app/commerce-modules/promotion/extend/page.mdx": "2024-12-09T16:19:19.364Z", "app/commerce-modules/promotion/extend/page.mdx": "2024-12-11T09:07:24.137Z",
"app/commerce-modules/promotion/links-to-other-modules/page.mdx": "2024-10-09T14:51:37.194Z", "app/commerce-modules/promotion/links-to-other-modules/page.mdx": "2024-10-09T14:51:37.194Z",
"app/commerce-modules/order/edit/page.mdx": "2024-10-09T08:50:05.334Z", "app/commerce-modules/order/edit/page.mdx": "2024-10-09T08:50:05.334Z",
"app/commerce-modules/order/links-to-other-modules/page.mdx": "2024-10-09T11:23:05.488Z", "app/commerce-modules/order/links-to-other-modules/page.mdx": "2024-10-09T11:23:05.488Z",
@@ -2246,7 +2246,7 @@ export const generatedEditDates = {
"app/commerce-modules/sales-channel/links-to-other-modules/page.mdx": "2024-10-15T14:25:29.097Z", "app/commerce-modules/sales-channel/links-to-other-modules/page.mdx": "2024-10-15T14:25:29.097Z",
"app/commerce-modules/stock-location/links-to-other-modules/page.mdx": "2024-10-15T14:33:11.483Z", "app/commerce-modules/stock-location/links-to-other-modules/page.mdx": "2024-10-15T14:33:11.483Z",
"app/commerce-modules/store/links-to-other-modules/page.mdx": "2024-06-26T07:19:49.931Z", "app/commerce-modules/store/links-to-other-modules/page.mdx": "2024-06-26T07:19:49.931Z",
"app/examples/page.mdx": "2024-12-09T16:19:18.598Z", "app/examples/page.mdx": "2024-12-11T09:07:47.589Z",
"app/medusa-cli/commands/build/page.mdx": "2024-11-11T11:00:49.665Z", "app/medusa-cli/commands/build/page.mdx": "2024-11-11T11:00:49.665Z",
"app/js-sdk/page.mdx": "2024-10-16T12:12:34.512Z", "app/js-sdk/page.mdx": "2024-10-16T12:12:34.512Z",
"references/js_sdk/admin/Admin/properties/js_sdk.admin.Admin.apiKey/page.mdx": "2024-12-09T13:21:58.136Z", "references/js_sdk/admin/Admin/properties/js_sdk.admin.Admin.apiKey/page.mdx": "2024-12-09T13:21:58.136Z",