fix lint errors
This commit is contained in:
1 parent
3522c0f0e0
commit
35a8224497
9 files changed
+51
-51
No files matched your search
@@ -185,7 +185,7 @@ Add the `validateAndTransformQuery` middleware to the API route in the file `src
|
|||||||
```ts title="src/api/middlewares.ts"
|
```ts title="src/api/middlewares.ts"
|
||||||
import {
|
import {
|
||||||
validateAndTransformQuery,
|
validateAndTransformQuery,
|
||||||
defineMiddlewares
|
defineMiddlewares,
|
||||||
} from "@medusajs/framework/http"
|
} from "@medusajs/framework/http"
|
||||||
import { PostStoreCustomSchema } from "./custom/validators"
|
import { PostStoreCustomSchema } from "./custom/validators"
|
||||||
|
|
||||||
|
|||||||
@@ -300,7 +300,7 @@ The first step is to use the `validateAndTransformQuery` middleware on the `GET`
|
|||||||
```ts title="src/api/middlewares.ts"
|
```ts title="src/api/middlewares.ts"
|
||||||
import {
|
import {
|
||||||
validateAndTransformQuery,
|
validateAndTransformQuery,
|
||||||
defineMiddlewares
|
defineMiddlewares,
|
||||||
} from "@medusajs/framework/http"
|
} from "@medusajs/framework/http"
|
||||||
import { createFindParams } from "@medusajs/medusa/api/utils/validators"
|
import { createFindParams } from "@medusajs/medusa/api/utils/validators"
|
||||||
|
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ const { isActive } = when(
|
|||||||
const isActive = isActiveStep()
|
const isActive = isActiveStep()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isActive
|
isActive,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -567,8 +567,8 @@ 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"
|
"delete-cart-custom-link",
|
||||||
{
|
{
|
||||||
input,
|
input,
|
||||||
carts,
|
carts,
|
||||||
}, (data) =>
|
}, (data) =>
|
||||||
|
|||||||
@@ -542,8 +542,8 @@ 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"
|
"create-customer-custom-link",
|
||||||
{
|
{
|
||||||
input,
|
input,
|
||||||
customers,
|
customers,
|
||||||
}, (data) =>
|
}, (data) =>
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ export const PostStoreCustomSchema = z.object({
|
|||||||
```ts title="src/api/middlewares.ts" highlights={[["13", "validateAndTransformBody"]]}
|
```ts title="src/api/middlewares.ts" highlights={[["13", "validateAndTransformBody"]]}
|
||||||
import {
|
import {
|
||||||
validateAndTransformBody,
|
validateAndTransformBody,
|
||||||
defineMiddlewares
|
defineMiddlewares,
|
||||||
} from "@medusajs/framework/http"
|
} from "@medusajs/framework/http"
|
||||||
import { PostStoreCustomSchema } from "./custom/validators"
|
import { PostStoreCustomSchema } from "./custom/validators"
|
||||||
|
|
||||||
@@ -629,7 +629,7 @@ import type {
|
|||||||
MedusaNextFunction,
|
MedusaNextFunction,
|
||||||
MedusaRequest,
|
MedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
defineMiddlewares
|
defineMiddlewares,
|
||||||
} from "@medusajs/framework/http"
|
} from "@medusajs/framework/http"
|
||||||
import { ConfigModule } from "@medusajs/framework/types"
|
import { ConfigModule } from "@medusajs/framework/types"
|
||||||
import { parseCorsOrigins } from "@medusajs/framework/utils"
|
import { parseCorsOrigins } from "@medusajs/framework/utils"
|
||||||
|
|||||||
@@ -695,17 +695,17 @@ export const syncStep = createStep(
|
|||||||
const sanityModule: SanityModuleService = container.resolve(SANITY_MODULE)
|
const sanityModule: SanityModuleService = container.resolve(SANITY_MODULE)
|
||||||
const query = container.resolve(ContainerRegistrationKeys.QUERY)
|
const query = container.resolve(ContainerRegistrationKeys.QUERY)
|
||||||
|
|
||||||
let total = 0;
|
const total = 0
|
||||||
const upsertMap: {
|
const upsertMap: {
|
||||||
before: any
|
before: any
|
||||||
after: any
|
after: any
|
||||||
}[] = []
|
}[] = []
|
||||||
|
|
||||||
const batchSize = 200;
|
const batchSize = 200
|
||||||
let hasMore = true;
|
const hasMore = true
|
||||||
let offset = 0;
|
const offset = 0
|
||||||
let filters = input.product_ids ? {
|
const filters = input.product_ids ? {
|
||||||
id: input.product_ids
|
id: input.product_ids,
|
||||||
} : {}
|
} : {}
|
||||||
|
|
||||||
while (hasMore) {
|
while (hasMore) {
|
||||||
@@ -772,16 +772,16 @@ while (hasMore) {
|
|||||||
const after = await sanityModule.upsertSyncDocument(
|
const after = await sanityModule.upsertSyncDocument(
|
||||||
"product",
|
"product",
|
||||||
prod as ProductDTO
|
prod as ProductDTO
|
||||||
);
|
)
|
||||||
|
|
||||||
upsertMap.push({
|
upsertMap.push({
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
before: prod.sanity_product,
|
before: prod.sanity_product,
|
||||||
after
|
after,
|
||||||
})
|
})
|
||||||
|
|
||||||
return after
|
return after
|
||||||
}),
|
})
|
||||||
)
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return StepResponse.permanentFailure(
|
return StepResponse.permanentFailure(
|
||||||
@@ -805,7 +805,7 @@ You also wrap the `promiseAll` function within a try-catch block. In the catch b
|
|||||||
Finally, after the `while` loop and at the end of the step, add the following return statement:
|
Finally, after the `while` loop and at the end of the step, add the following return statement:
|
||||||
|
|
||||||
```ts title="src/workflows/sanity-sync-products/steps/sync.ts"
|
```ts title="src/workflows/sanity-sync-products/steps/sync.ts"
|
||||||
return new StepResponse({ total }, upsertMap);
|
return new StepResponse({ total }, upsertMap)
|
||||||
```
|
```
|
||||||
|
|
||||||
If no errors occur, the step returns an instance of `StepResponse`, which must be returned by any step. It accepts as a first parameter the data to return to the workflow that executed this step.
|
If no errors occur, the step returns an instance of `StepResponse`, which must be returned by any step. It accepts as a first parameter the data to return to the workflow that executed this step.
|
||||||
|
|||||||
@@ -440,7 +440,7 @@ export const validateVariantOutOfStockStep = createStep(
|
|||||||
const query = container.resolve("query")
|
const query = container.resolve("query")
|
||||||
const availability = await getVariantAvailability(query, {
|
const availability = await getVariantAvailability(query, {
|
||||||
variant_ids: [variant_id],
|
variant_ids: [variant_id],
|
||||||
sales_channel_id
|
sales_channel_id,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (availability[variant_id].availability > 0) {
|
if (availability[variant_id].availability > 0) {
|
||||||
@@ -623,10 +623,10 @@ export const createRestockSubscriptionWorkflow = createWorkflow(
|
|||||||
({
|
({
|
||||||
variant_id,
|
variant_id,
|
||||||
sales_channel_id,
|
sales_channel_id,
|
||||||
customer
|
customer,
|
||||||
}: CreateRestockSubscriptionWorkflowInput) => {
|
}: CreateRestockSubscriptionWorkflowInput) => {
|
||||||
const customerId = transform({
|
const customerId = transform({
|
||||||
customer
|
customer,
|
||||||
}, (data) => {
|
}, (data) => {
|
||||||
return data.customer.customer_id || ""
|
return data.customer.customer_id || ""
|
||||||
})
|
})
|
||||||
@@ -643,8 +643,8 @@ export const createRestockSubscriptionWorkflow = createWorkflow(
|
|||||||
fields: ["email"],
|
fields: ["email"],
|
||||||
filters: { id: customerId },
|
filters: { id: customerId },
|
||||||
options: {
|
options: {
|
||||||
throwIfKeyNotFound: true
|
throwIfKeyNotFound: true,
|
||||||
}
|
},
|
||||||
}).config({ name: "retrieve-customer" })
|
}).config({ name: "retrieve-customer" })
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@@ -652,7 +652,7 @@ export const createRestockSubscriptionWorkflow = createWorkflow(
|
|||||||
|
|
||||||
const email = transform({
|
const email = transform({
|
||||||
retrievedCustomer,
|
retrievedCustomer,
|
||||||
customer
|
customer,
|
||||||
}, (data) => {
|
}, (data) => {
|
||||||
return data.customer?.email ?? data.retrievedCustomer?.[0].email
|
return data.customer?.email ?? data.retrievedCustomer?.[0].email
|
||||||
})
|
})
|
||||||
@@ -692,7 +692,7 @@ export const subscriptionWorkflow2Highlights = [
|
|||||||
```ts title="src/workflows/create-restock-subscription/index.ts" highlights={subscriptionWorkflow2Highlights}
|
```ts title="src/workflows/create-restock-subscription/index.ts" highlights={subscriptionWorkflow2Highlights}
|
||||||
validateVariantOutOfStockStep({
|
validateVariantOutOfStockStep({
|
||||||
variant_id,
|
variant_id,
|
||||||
sales_channel_id
|
sales_channel_id,
|
||||||
})
|
})
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -702,8 +702,8 @@ const { data: restockSubscriptions } = useQueryGraphStep({
|
|||||||
filters: {
|
filters: {
|
||||||
email,
|
email,
|
||||||
variant_id,
|
variant_id,
|
||||||
sales_channel_id
|
sales_channel_id,
|
||||||
}
|
},
|
||||||
}).config({ name: "retrieve-subscriptions" })
|
}).config({ name: "retrieve-subscriptions" })
|
||||||
|
|
||||||
when({ restockSubscriptions }, ({ restockSubscriptions }) => {
|
when({ restockSubscriptions }, ({ restockSubscriptions }) => {
|
||||||
@@ -714,7 +714,7 @@ when({ restockSubscriptions }, ({ restockSubscriptions }) => {
|
|||||||
variant_id,
|
variant_id,
|
||||||
sales_channel_id,
|
sales_channel_id,
|
||||||
email,
|
email,
|
||||||
customer_id: customer.customer_id
|
customer_id: customer.customer_id,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -724,7 +724,7 @@ when({ restockSubscriptions }, ({ restockSubscriptions }) => {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
updateRestockSubscriptionStep({
|
updateRestockSubscriptionStep({
|
||||||
id: restockSubscriptions[0].id,
|
id: restockSubscriptions[0].id,
|
||||||
customer_id: customer.customer_id
|
customer_id: customer.customer_id,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -735,8 +735,8 @@ const { data: restockSubscription } = useQueryGraphStep({
|
|||||||
filters: {
|
filters: {
|
||||||
email,
|
email,
|
||||||
variant_id,
|
variant_id,
|
||||||
sales_channel_id
|
sales_channel_id,
|
||||||
}
|
},
|
||||||
}).config({ name: "retrieve-restock-subscription" })
|
}).config({ name: "retrieve-restock-subscription" })
|
||||||
|
|
||||||
return new WorkflowResponse(
|
return new WorkflowResponse(
|
||||||
@@ -1120,12 +1120,12 @@ Before adding the step that does this, you'll add a method in the `RestockModule
|
|||||||
|
|
||||||
```ts title="src/modules/restock/service.ts"
|
```ts title="src/modules/restock/service.ts"
|
||||||
// other imports...
|
// other imports...
|
||||||
import { InjectManager, MedusaContext } from "@medusajs/framework/utils";
|
import { InjectManager, MedusaContext } from "@medusajs/framework/utils"
|
||||||
import { Context } from "@medusajs/framework/types"
|
import { Context } from "@medusajs/framework/types"
|
||||||
import { EntityManager } from "@mikro-orm/knex";
|
import { EntityManager } from "@mikro-orm/knex"
|
||||||
|
|
||||||
class RestockModuleService extends MedusaService({
|
class RestockModuleService extends MedusaService({
|
||||||
RestockSubscription
|
RestockSubscription,
|
||||||
}) {
|
}) {
|
||||||
// ...
|
// ...
|
||||||
@InjectManager()
|
@InjectManager()
|
||||||
@@ -1151,9 +1151,9 @@ You'll use this method in the step. To create the step, create the file `src/wor
|
|||||||

|

|
||||||
|
|
||||||
```ts title="src/workflows/send-restock-notifications/steps/get-distinct-subscriptions.ts"
|
```ts title="src/workflows/send-restock-notifications/steps/get-distinct-subscriptions.ts"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk";
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
import RestockModuleService from "../../../modules/restock/service";
|
import RestockModuleService from "../../../modules/restock/service"
|
||||||
import { RESTOCK_MODULE } from "../../../modules/restock";
|
import { RESTOCK_MODULE } from "../../../modules/restock"
|
||||||
|
|
||||||
export const getDistinctSubscriptionsStep = createStep(
|
export const getDistinctSubscriptionsStep = createStep(
|
||||||
"get-distinct-subscriptions",
|
"get-distinct-subscriptions",
|
||||||
@@ -1198,7 +1198,7 @@ export const getRestockedStep = createStep(
|
|||||||
input.map(async (restockSubscription) => {
|
input.map(async (restockSubscription) => {
|
||||||
const variantAvailability = await getVariantAvailability(query, {
|
const variantAvailability = await getVariantAvailability(query, {
|
||||||
variant_ids: [restockSubscription.variant_id],
|
variant_ids: [restockSubscription.variant_id],
|
||||||
sales_channel_id: restockSubscription.sales_channel_id
|
sales_channel_id: restockSubscription.sales_channel_id,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (variantAvailability[restockSubscription.variant_id].availability > 0) {
|
if (variantAvailability[restockSubscription.variant_id].availability > 0) {
|
||||||
@@ -1322,12 +1322,12 @@ Create the file `src/workflows/send-restock-notifications/index.ts` with the fol
|
|||||||

|

|
||||||
|
|
||||||
```ts title="src/workflows/send-restock-notifications/index.ts"
|
```ts title="src/workflows/send-restock-notifications/index.ts"
|
||||||
import { createWorkflow, transform, WorkflowResponse } from "@medusajs/framework/workflows-sdk";
|
import { createWorkflow, transform, WorkflowResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
import { useQueryGraphStep } from "@medusajs/medusa/core-flows";
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
|
||||||
import { getRestockedStep } from "./steps/get-restocked";
|
import { getRestockedStep } from "./steps/get-restocked"
|
||||||
import { sendRestockNotificationStep } from "./steps/send-restock-notification";
|
import { sendRestockNotificationStep } from "./steps/send-restock-notification"
|
||||||
import { deleteRestockSubscriptionStep } from "./steps/delete-restock-subscriptions";
|
import { deleteRestockSubscriptionStep } from "./steps/delete-restock-subscriptions"
|
||||||
import { getDistinctSubscriptionsStep } from "./steps/get-distinct-subscriptions";
|
import { getDistinctSubscriptionsStep } from "./steps/get-distinct-subscriptions"
|
||||||
|
|
||||||
export const sendRestockNotificationsWorkflow = createWorkflow(
|
export const sendRestockNotificationsWorkflow = createWorkflow(
|
||||||
"send-restock-notifications",
|
"send-restock-notifications",
|
||||||
@@ -1338,11 +1338,11 @@ export const sendRestockNotificationsWorkflow = createWorkflow(
|
|||||||
const restockedSubscriptions = getRestockedStep(subscriptions)
|
const restockedSubscriptions = getRestockedStep(subscriptions)
|
||||||
|
|
||||||
const { variant_ids, sales_channel_ids } = transform({
|
const { variant_ids, sales_channel_ids } = transform({
|
||||||
restockedSubscriptions
|
restockedSubscriptions,
|
||||||
}, (data) => {
|
}, (data) => {
|
||||||
const filters: Record<string, string[]> = {
|
const filters: Record<string, string[]> = {
|
||||||
variant_ids: [],
|
variant_ids: [],
|
||||||
sales_channel_ids: []
|
sales_channel_ids: [],
|
||||||
}
|
}
|
||||||
data.restockedSubscriptions.map((subscription) => {
|
data.restockedSubscriptions.map((subscription) => {
|
||||||
filters.variant_ids.push(subscription.variant_id)
|
filters.variant_ids.push(subscription.variant_id)
|
||||||
@@ -1358,8 +1358,8 @@ export const sendRestockNotificationsWorkflow = createWorkflow(
|
|||||||
fields: ["*", "product_variant.*"],
|
fields: ["*", "product_variant.*"],
|
||||||
filters: {
|
filters: {
|
||||||
variant_id: variant_ids,
|
variant_id: variant_ids,
|
||||||
sales_channel_id: sales_channel_ids
|
sales_channel_id: sales_channel_ids,
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -1369,7 +1369,7 @@ export const sendRestockNotificationsWorkflow = createWorkflow(
|
|||||||
deleteRestockSubscriptionStep(restockedSubscriptionsWithEmails)
|
deleteRestockSubscriptionStep(restockedSubscriptionsWithEmails)
|
||||||
|
|
||||||
return new WorkflowResponse({
|
return new WorkflowResponse({
|
||||||
subscriptions: restockedSubscriptionsWithEmails
|
subscriptions: restockedSubscriptionsWithEmails,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ This occurs if the `when-then` block doesn't return a step's result and doesn't
|
|||||||
|
|
||||||
```ts
|
```ts
|
||||||
const result = when(
|
const result = when(
|
||||||
"custom-when-condition",
|
"custom-when-condition"
|
||||||
// ... rest of the parameters
|
// ... rest of the parameters
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in new issue
Block a user