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,10 +529,13 @@ 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(
"create-cart-custom-link",
{
input, input,
carts, carts,
}, (data) => },
(data) =>
!data.carts[0].custom && !data.carts[0].custom &&
data.input.additional_data?.custom_name?.length > 0 data.input.additional_data?.custom_name?.length > 0
) )
@@ -563,7 +566,9 @@ 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(
"delete-cart-custom-link"
{
input, input,
carts, carts,
}, (data) => }, (data) =>
@@ -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,7 +541,9 @@ 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(
"create-customer-custom-link"
{
input, input,
customers, customers,
}, (data) => }, (data) =>
@@ -575,7 +577,9 @@ 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(
"delete-customer-custom-link",
{
input, input,
customers, customers,
}, (data) => }, (data) =>
@@ -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,7 +547,9 @@ 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(
"create-product-custom-link",
{
input, input,
products, products,
}, (data) => }, (data) =>
@@ -581,7 +583,9 @@ 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(
"delete-product-custom-link",
{
input, input,
products, products,
}, (data) => }, (data) =>
@@ -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,7 +553,9 @@ 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(
"create-promotion-custom-link",
{
input, input,
promotions, promotions,
}, (data) => }, (data) =>
@@ -587,7 +589,9 @@ 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(
"delete-promotion-custom-link",
{
input, input,
promotions, promotions,
}, (data) => }, (data) =>
@@ -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",