chore(medusa, workflows-sdk): Workflow default to throw the first error (#7442)

**What**
Currently when a workflow fail it will throw an error which contains the messages of all error thrown durring the workflow lifetime. Therefore, in our cases we are always preventing workflow to throw and grab the first error that we then re throw.
This pr eliminate that need by throwing back the first error among the error thrown by a workflow as it is the main case. In case someone need a special handling they can still set the option throwOnError to false and handle the error the way they need
This commit is contained in:
Adrien de Peretti authored and GitHub committed 2024-05-24 12:55:05 +00:00
1 parent 16651f9849
commit fff1b3ef9c
109 files changed
+145 -771

No files matched your search

@@ -1 +0,0 @@
export const emptyHandler: any = () => {}
@@ -1,5 +1,4 @@
export * from "./merge-data" export * from "./merge-data"
export * from "./empty-handler"
export * from "./pipe" export * from "./pipe"
export * from "./workflow-export" export * from "./workflow-export"
export * from "./type" export * from "./type"
@@ -4,6 +4,7 @@ import { isObject } from "@medusajs/utils"
/** /**
* Pipe utils that merges data from an object into a new object. * Pipe utils that merges data from an object into a new object.
* The new object will have a target key with the merged data from the keys if specified. * The new object will have a target key with the merged data from the keys if specified.
* @deprecated
* @param keys * @param keys
* @param target * @param target
*/ */
@@ -66,6 +66,11 @@ export type PipelineHandler<T extends any = undefined> = (
: T : T
> >
/**
* @deprecated
* @param input
* @param functions
*/
export function pipe<T>( export function pipe<T>(
input: PipelineInput, input: PipelineInput,
...functions: [...PipelineHandler[], PipelineHandler<T>] ...functions: [...PipelineHandler[], PipelineHandler<T>]
@@ -5,7 +5,7 @@ import {
TransactionState, TransactionState,
} from "@medusajs/orchestration" } from "@medusajs/orchestration"
import { LoadedModule, MedusaContainer } from "@medusajs/types" import { LoadedModule, MedusaContainer } from "@medusajs/types"
import { MedusaContextType, isPresent } from "@medusajs/utils" import { isPresent, MedusaContextType } from "@medusajs/utils"
import { EOL } from "os" import { EOL } from "os"
import { ulid } from "ulid" import { ulid } from "ulid"
import { MedusaWorkflow } from "../medusa-workflow" import { MedusaWorkflow } from "../medusa-workflow"
@@ -87,10 +87,11 @@ function createContextualWorkflowRunner<
failedStatus.includes(transaction.getState()) && failedStatus.includes(transaction.getState()) &&
throwOnError throwOnError
) { ) {
const errorMessage = errors /*const errorMessage = errors
?.map((err) => `${err.error?.message}${EOL}${err.error?.stack}`) ?.map((err) => `${err.error?.message}${EOL}${err.error?.stack}`)
?.join(`${EOL}`) ?.join(`${EOL}`)*/
throw new Error(errorMessage) const firstError = errors?.[0]?.error ?? new Error("Unknown error")
throw firstError
} }
let result let result
@@ -10,7 +10,7 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminRevokeApiKeyType>, req: AuthenticatedMedusaRequest<AdminRevokeApiKeyType>,
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { errors } = await revokeApiKeysWorkflow(req.scope).run({ await revokeApiKeysWorkflow(req.scope).run({
input: { input: {
selector: { id: req.params.id }, selector: { id: req.params.id },
revoke: { revoke: {
@@ -18,13 +18,8 @@ export const POST = async (
revoked_by: req.auth_context.actor_id, revoked_by: req.auth_context.actor_id,
}, },
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const apiKey = await refetchApiKey( const apiKey = await refetchApiKey(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -27,18 +27,13 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminUpdateApiKeyType>, req: AuthenticatedMedusaRequest<AdminUpdateApiKeyType>,
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { errors } = await updateApiKeysWorkflow(req.scope).run({ await updateApiKeysWorkflow(req.scope).run({
input: { input: {
selector: { id: req.params.id }, selector: { id: req.params.id },
update: req.validatedBody, update: req.validatedBody,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const apiKey = await refetchApiKey( const apiKey = await refetchApiKey(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -54,15 +49,10 @@ export const DELETE = async (
) => { ) => {
const id = req.params.id const id = req.params.id
const { errors } = await deleteApiKeysWorkflow(req.scope).run({ await deleteApiKeysWorkflow(req.scope).run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "api_key", object: "api_key",
@@ -21,19 +21,14 @@ export const POST = async (
) )
} }
const { errors } = await linkSalesChannelsToApiKeyWorkflow(req.scope).run({ await linkSalesChannelsToApiKeyWorkflow(req.scope).run({
input: { input: {
id: req.params.id, id: req.params.id,
add, add,
remove, remove,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const updatedApiKey = await refetchApiKey( const updatedApiKey = await refetchApiKey(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -1,4 +1,4 @@
import { createApiKeysWorkflow } from "@medusajs/core-flows" import {createApiKeysWorkflow} from "@medusajs/core-flows"
import { import {
ContainerRegistrationKeys, ContainerRegistrationKeys,
remoteQueryObjectFromString, remoteQueryObjectFromString,
@@ -7,7 +7,7 @@ import {
AuthenticatedMedusaRequest, AuthenticatedMedusaRequest,
MedusaResponse, MedusaResponse,
} from "../../../types/routing" } from "../../../types/routing"
import { AdminCreateApiKeyType } from "./validators" import {AdminCreateApiKeyType} from "./validators"
export const GET = async ( export const GET = async (
req: AuthenticatedMedusaRequest, req: AuthenticatedMedusaRequest,
@@ -45,15 +45,10 @@ export const POST = async (
}, },
] ]
const { result, errors } = await createApiKeysWorkflow(req.scope).run({ const { result } = await createApiKeysWorkflow(req.scope).run({
input: { api_keys: input }, input: { api_keys: input },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
// We should not refetch the api key here, as we need to show the secret key in the response (and never again) // We should not refetch the api key here, as we need to show the secret key in the response (and never again)
// And the only time we get to see the secret, is when we create it // And the only time we get to see the secret, is when we create it
res.status(200).json({ api_key: result[0] }) res.status(200).json({ api_key: result[0] })
@@ -13,16 +13,9 @@ export const POST = async (
) => { ) => {
const { id } = req.params const { id } = req.params
const { add, remove } = req.validatedBody const { add, remove } = req.validatedBody
const { errors } = await addOrRemoveCampaignPromotionsWorkflow(req.scope).run( await addOrRemoveCampaignPromotionsWorkflow(req.scope).run({
{
input: { id, add, remove }, input: { id, add, remove },
throwOnError: false, })
}
)
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const campaign = await refetchCampaign( const campaign = await refetchCampaign(
req.params.id, req.params.id,
@@ -43,15 +43,10 @@ export const POST = async (
}, },
] ]
const { errors } = await updateCampaigns.run({ await updateCampaigns.run({
input: { campaignsData }, input: { campaignsData },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const campaign = await refetchCampaign( const campaign = await refetchCampaign(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -67,15 +62,10 @@ export const DELETE = async (
const id = req.params.id const id = req.params.id
const deleteCampaigns = deleteCampaignsWorkflow(req.scope) const deleteCampaigns = deleteCampaignsWorkflow(req.scope)
const { errors } = await deleteCampaigns.run({ await deleteCampaigns.run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "campaign", object: "campaign",
@@ -2,13 +2,13 @@ import {
AuthenticatedMedusaRequest, AuthenticatedMedusaRequest,
MedusaResponse, MedusaResponse,
} from "../../../types/routing" } from "../../../types/routing"
import { createCampaignsWorkflow } from "@medusajs/core-flows" import {createCampaignsWorkflow} from "@medusajs/core-flows"
import { import {
ContainerRegistrationKeys, ContainerRegistrationKeys,
remoteQueryObjectFromString, remoteQueryObjectFromString,
} from "@medusajs/utils" } from "@medusajs/utils"
import { AdminCreateCampaignType } from "./validators" import {AdminCreateCampaignType} from "./validators"
import { refetchCampaign } from "./helpers" import {refetchCampaign} from "./helpers"
export const GET = async ( export const GET = async (
req: AuthenticatedMedusaRequest, req: AuthenticatedMedusaRequest,
@@ -42,18 +42,13 @@ export const POST = async (
const createCampaigns = createCampaignsWorkflow(req.scope) const createCampaigns = createCampaignsWorkflow(req.scope)
const campaignsData = [req.validatedBody] const campaignsData = [req.validatedBody]
const { result, errors } = await createCampaigns.run({ const { result } = await createCampaigns.run({
input: { campaignsData }, input: { campaignsData },
throwOnError: false,
context: { context: {
requestId: req.requestId, requestId: req.requestId,
}, },
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const campaign = await refetchCampaign( const campaign = await refetchCampaign(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -14,19 +14,14 @@ export const POST = async (
const { add = [], remove = [] } = req.validatedBody const { add = [], remove = [] } = req.validatedBody
const workflow = batchLinkProductsToCollectionWorkflow(req.scope) const workflow = batchLinkProductsToCollectionWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { input: {
id, id,
add, add,
remove, remove,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const collection = await refetchCollection( const collection = await refetchCollection(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -27,18 +27,13 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminUpdateCollectionType>, req: AuthenticatedMedusaRequest<AdminUpdateCollectionType>,
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { errors } = await updateCollectionsWorkflow(req.scope).run({ await updateCollectionsWorkflow(req.scope).run({
input: { input: {
selector: { id: req.params.id }, selector: { id: req.params.id },
update: req.validatedBody, update: req.validatedBody,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const collection = await refetchCollection( const collection = await refetchCollection(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -54,15 +49,10 @@ export const DELETE = async (
) => { ) => {
const id = req.params.id const id = req.params.id
const { errors } = await deleteCollectionsWorkflow(req.scope).run({ await deleteCollectionsWorkflow(req.scope).run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "collection", object: "collection",
@@ -46,15 +46,10 @@ export const POST = async (
}, },
] ]
const { result, errors } = await createCollectionsWorkflow(req.scope).run({ const { result } = await createCollectionsWorkflow(req.scope).run({
input: { collections: input }, input: { collections: input },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const collection = await refetchCollection( const collection = await refetchCollection(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -15,19 +15,14 @@ export const POST = async (
const { add, remove } = req.validatedBody const { add, remove } = req.validatedBody
const workflow = linkCustomersToCustomerGroupWorkflow(req.scope) const workflow = linkCustomersToCustomerGroupWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { input: {
id, id,
add, add,
remove, remove,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const customerGroup = await refetchCustomerGroup( const customerGroup = await refetchCustomerGroup(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -28,18 +28,13 @@ export const POST = async (
res: MedusaResponse res: MedusaResponse
) => { ) => {
const updateGroups = updateCustomerGroupsWorkflow(req.scope) const updateGroups = updateCustomerGroupsWorkflow(req.scope)
const { errors } = await updateGroups.run({ await updateGroups.run({
input: { input: {
selector: { id: req.params.id }, selector: { id: req.params.id },
update: req.validatedBody, update: req.validatedBody,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const customerGroup = await refetchCustomerGroup( const customerGroup = await refetchCustomerGroup(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -55,15 +50,10 @@ export const DELETE = async (
const id = req.params.id const id = req.params.id
const deleteCustomerGroups = deleteCustomerGroupsWorkflow(req.scope) const deleteCustomerGroups = deleteCustomerGroupsWorkflow(req.scope)
const { errors } = await deleteCustomerGroups.run({ await deleteCustomerGroups.run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "customer_group", object: "customer_group",
@@ -47,15 +47,10 @@ export const POST = async (
}, },
] ]
const { result, errors } = await createGroups.run({ const { result } = await createGroups.run({
input: { customersData }, input: { customersData },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const customerGroup = await refetchCustomerGroup( const customerGroup = await refetchCustomerGroup(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -37,18 +37,13 @@ export const POST = async (
res: MedusaResponse res: MedusaResponse
) => { ) => {
const updateAddresses = updateCustomerAddressesWorkflow(req.scope) const updateAddresses = updateCustomerAddressesWorkflow(req.scope)
const { errors } = await updateAddresses.run({ await updateAddresses.run({
input: { input: {
selector: { id: req.params.address_id, customer_id: req.params.id }, selector: { id: req.params.address_id, customer_id: req.params.id },
update: req.validatedBody, update: req.validatedBody,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const customer = await refetchCustomer( const customer = await refetchCustomer(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -65,15 +60,10 @@ export const DELETE = async (
const id = req.params.address_id const id = req.params.address_id
const deleteAddress = deleteCustomerAddressesWorkflow(req.scope) const deleteAddress = deleteCustomerAddressesWorkflow(req.scope)
const { errors } = await deleteAddress.run({ await deleteAddress.run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const customer = await refetchCustomer( const customer = await refetchCustomer(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -49,15 +49,10 @@ export const POST = async (
}, },
] ]
const { errors } = await createAddresses.run({ await createAddresses.run({
input: { addresses }, input: { addresses },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const customer = await refetchCustomer( const customer = await refetchCustomer(
customerId, customerId,
req.scope, req.scope,
@@ -35,18 +35,13 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminUpdateCustomerType>, req: AuthenticatedMedusaRequest<AdminUpdateCustomerType>,
res: MedusaResponse<{ customer: AdminCustomer }> res: MedusaResponse<{ customer: AdminCustomer }>
) => { ) => {
const { errors } = await updateCustomersWorkflow(req.scope).run({ await updateCustomersWorkflow(req.scope).run({
input: { input: {
selector: { id: req.params.id }, selector: { id: req.params.id },
update: req.validatedBody, update: req.validatedBody,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const customer = await refetchCustomer( const customer = await refetchCustomer(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -62,15 +57,10 @@ export const DELETE = async (
const id = req.params.id const id = req.params.id
const deleteCustomers = deleteCustomersWorkflow(req.scope) const deleteCustomers = deleteCustomersWorkflow(req.scope)
const { errors } = await deleteCustomers.run({ await deleteCustomers.run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "customer", object: "customer",
@@ -50,15 +50,10 @@ export const POST = async (
}, },
] ]
const { result, errors } = await createCustomers.run({ const { result } = await createCustomers.run({
input: { customersData }, input: { customersData },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const customer = await refetchCustomer( const customer = await refetchCustomer(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -76,15 +76,10 @@ export const POST = async (
input.email = customer?.email input.email = customer?.email
} }
const { result, errors } = await createOrdersWorkflow(req.scope).run({ const { result } = await createOrdersWorkflow(req.scope).run({
input: workflowInput, input: workflowInput,
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const draftOrder = await refetchOrder( const draftOrder = await refetchOrder(
result.id, result.id,
req.scope, req.scope,
@@ -12,15 +12,10 @@ export const DELETE = async (
) => { ) => {
const { id } = req.params const { id } = req.params
const { errors } = await deleteFulfillmentSetsWorkflow(req.scope).run({ await deleteFulfillmentSetsWorkflow(req.scope).run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "fulfillment_set", object: "fulfillment_set",
@@ -75,15 +75,10 @@ export const POST = async (
update: req.validatedBody, update: req.validatedBody,
} }
const { errors } = await updateServiceZonesWorkflow(req.scope).run({ await updateServiceZonesWorkflow(req.scope).run({
input: workflowInput, input: workflowInput,
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const [fulfillment_set] = await remoteQuery( const [fulfillment_set] = await remoteQuery(
remoteQueryObjectFromString({ remoteQueryObjectFromString({
entryPoint: "fulfillment_sets", entryPoint: "fulfillment_sets",
@@ -119,15 +114,10 @@ export const DELETE = async (
) )
} }
const { errors } = await deleteServiceZonesWorkflow(req.scope).run({ await deleteServiceZonesWorkflow(req.scope).run({
input: { ids: [zone_id] }, input: { ids: [zone_id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id: zone_id, id: zone_id,
object: "service-zone", object: "service-zone",
@@ -17,15 +17,10 @@ export const POST = async (
], ],
} }
const { errors } = await createServiceZonesWorkflow(req.scope).run({ await createServiceZonesWorkflow(req.scope).run({
input: workflowInput, input: workflowInput,
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const fulfillmentSet = await refetchFulfillmentSet( const fulfillmentSet = await refetchFulfillmentSet(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -11,15 +11,10 @@ export const POST = async (
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { id } = req.params const { id } = req.params
const { errors } = await cancelFulfillmentWorkflow(req.scope).run({ await cancelFulfillmentWorkflow(req.scope).run({
input: { id }, input: { id },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const fulfillment = await refetchFulfillment( const fulfillment = await refetchFulfillment(
id, id,
req.scope, req.scope,
@@ -12,15 +12,10 @@ export const POST = async (
) => { ) => {
const { id } = req.params const { id } = req.params
const { errors } = await createShipmentWorkflow(req.scope).run({ await createShipmentWorkflow(req.scope).run({
input: { id, ...req.validatedBody }, input: { id, ...req.validatedBody },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const fulfillment = await refetchFulfillment( const fulfillment = await refetchFulfillment(
id, id,
req.scope, req.scope,
@@ -10,17 +10,12 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminCreateFulfillmentType>, req: AuthenticatedMedusaRequest<AdminCreateFulfillmentType>,
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { result: fullfillment, errors } = await createFulfillmentWorkflow( const { result: fullfillment } = await createFulfillmentWorkflow(
req.scope req.scope
).run({ ).run({
input: req.validatedBody, input: req.validatedBody,
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const fulfillment = await refetchFulfillment( const fulfillment = await refetchFulfillment(
fullfillment.id, fullfillment.id,
req.scope, req.scope,
@@ -64,17 +64,12 @@ export const POST = async (
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { id, location_id } = req.params const { id, location_id } = req.params
const { errors } = await updateInventoryLevelsWorkflow(req.scope).run({ await updateInventoryLevelsWorkflow(req.scope).run({
input: { input: {
updates: [{ ...req.validatedBody, inventory_item_id: id, location_id }], updates: [{ ...req.validatedBody, inventory_item_id: id, location_id }],
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const inventoryItem = await refetchInventoryItem( const inventoryItem = await refetchInventoryItem(
id, id,
req.scope, req.scope,
@@ -20,7 +20,7 @@ export const POST = async (
// TODO: Normalize workflow and response, and add support for updates // TODO: Normalize workflow and response, and add support for updates
const workflow = bulkCreateDeleteLevelsWorkflow(req.scope) const workflow = bulkCreateDeleteLevelsWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { input: {
deletes: deletes:
req.validatedBody.delete?.map((location_id) => ({ req.validatedBody.delete?.map((location_id) => ({
@@ -33,12 +33,7 @@ export const POST = async (
inventory_item_id: id, inventory_item_id: id,
})) ?? [], })) ?? [],
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ inventory_item: {} }) res.status(200).json({ inventory_item: {} })
} }
@@ -18,7 +18,7 @@ export const POST = async (
const { id } = req.params const { id } = req.params
const workflow = createInventoryLevelsWorkflow(req.scope) const workflow = createInventoryLevelsWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { input: {
inventory_levels: [ inventory_levels: [
{ {
@@ -27,13 +27,8 @@ export const POST = async (
}, },
], ],
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const inventoryItem = await refetchInventoryItem( const inventoryItem = await refetchInventoryItem(
id, id,
req.scope, req.scope,
@@ -60,15 +60,10 @@ export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => {
const id = req.params.id const id = req.params.id
const deleteInventoryItems = deleteInventoryItemWorkflow(req.scope) const deleteInventoryItems = deleteInventoryItemWorkflow(req.scope)
const { errors } = await deleteInventoryItems.run({ await deleteInventoryItems.run({
input: [id], input: [id],
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "inventory_item", object: "inventory_item",
@@ -35,15 +35,10 @@ export const DELETE = async (
const { id } = req.params const { id } = req.params
const workflow = deleteInvitesWorkflow(req.scope) const workflow = deleteInvitesWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "invite", object: "invite",
@@ -45,14 +45,9 @@ export const POST = async (
input: { input: {
invites: [req.validatedBody], invites: [req.validatedBody],
}, },
throwOnError: false,
} }
const { result, errors } = await workflow.run(input) const { result } = await workflow.run(input)
if (errors?.length) {
throw errors[0].error
}
const invite = await refetchInvite( const invite = await refetchInvite(
result[0].id, result[0].id,
@@ -13,15 +13,10 @@ export const POST = async (
const remoteQuery = req.scope.resolve("remoteQuery") const remoteQuery = req.scope.resolve("remoteQuery")
const { id } = req.params const { id } = req.params
const { errors } = await archiveOrderWorkflow(req.scope).run({ await archiveOrderWorkflow(req.scope).run({
input: { orderIds: [req.validatedBody.order_id] }, input: { orderIds: [req.validatedBody.order_id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const queryObject = remoteQueryObjectFromString({ const queryObject = remoteQueryObjectFromString({
entryPoint: "order", entryPoint: "order",
variables: { id }, variables: { id },
@@ -13,15 +13,10 @@ export const POST = async (
const remoteQuery = req.scope.resolve("remoteQuery") const remoteQuery = req.scope.resolve("remoteQuery")
const { id } = req.params const { id } = req.params
const { errors } = await completeOrderWorkflow(req.scope).run({ await completeOrderWorkflow(req.scope).run({
input: { orderIds: [req.validatedBody.order_id] }, input: { orderIds: [req.validatedBody.order_id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const queryObject = remoteQueryObjectFromString({ const queryObject = remoteQueryObjectFromString({
entryPoint: "order", entryPoint: "order",
variables: { id }, variables: { id },
@@ -12,19 +12,14 @@ export const POST = async (
) => { ) => {
const { id } = req.params const { id } = req.params
const { errors } = await capturePaymentWorkflow(req.scope).run({ await capturePaymentWorkflow(req.scope).run({
input: { input: {
payment_id: id, payment_id: id,
captured_by: req.auth_context.actor_id, captured_by: req.auth_context.actor_id,
amount: req.validatedBody.amount, amount: req.validatedBody.amount,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const payment = await refetchPayment( const payment = await refetchPayment(
id, id,
req.scope, req.scope,
@@ -11,19 +11,14 @@ export const POST = async (
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { id } = req.params const { id } = req.params
const { errors } = await refundPaymentWorkflow(req.scope).run({ await refundPaymentWorkflow(req.scope).run({
input: { input: {
payment_id: id, payment_id: id,
created_by: req.auth_context.actor_id, created_by: req.auth_context.actor_id,
amount: req.validatedBody.amount, amount: req.validatedBody.amount,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const payment = await refetchPayment( const payment = await refetchPayment(
id, id,
req.scope, req.scope,
@@ -29,7 +29,7 @@ export const POST = async (
} = req.validatedBody } = req.validatedBody
const workflow = batchPriceListPricesWorkflow(req.scope) const workflow = batchPriceListPricesWorkflow(req.scope)
const { result, errors } = await workflow.run({ const { result } = await workflow.run({
input: { input: {
data: { data: {
id, id,
@@ -38,13 +38,8 @@ export const POST = async (
delete: deletePriceIds, delete: deletePriceIds,
}, },
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const [created, updated] = await promiseAll([ const [created, updated] = await promiseAll([
listPrices( listPrices(
result.created.map((c) => c.id), result.created.map((c) => c.id),
@@ -34,7 +34,7 @@ export const POST = async (
) )
const workflow = batchPriceListPricesWorkflow(req.scope) const workflow = batchPriceListPricesWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { input: {
data: { data: {
id, id,
@@ -43,13 +43,8 @@ export const POST = async (
delete: productPriceIds, delete: productPriceIds,
}, },
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const priceList = await fetchPriceList( const priceList = await fetchPriceList(
id, id,
req.scope, req.scope,
@@ -29,15 +29,10 @@ export const POST = async (
const id = req.params.id const id = req.params.id
const workflow = updatePriceListsWorkflow(req.scope) const workflow = updatePriceListsWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { price_lists_data: [{ ...req.validatedBody, id }] }, input: { price_lists_data: [{ ...req.validatedBody, id }] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const price_list = await fetchPriceList( const price_list = await fetchPriceList(
id, id,
req.scope, req.scope,
@@ -54,15 +49,10 @@ export const DELETE = async (
const id = req.params.id const id = req.params.id
const workflow = deletePriceListsWorkflow(req.scope) const workflow = deletePriceListsWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "price_list", object: "price_list",
@@ -40,15 +40,10 @@ export const POST = async (
res: MedusaResponse res: MedusaResponse
) => { ) => {
const workflow = createPriceListsWorkflow(req.scope) const workflow = createPriceListsWorkflow(req.scope)
const { result, errors } = await workflow.run({ const { result } = await workflow.run({
input: { price_lists_data: [req.validatedBody] }, input: { price_lists_data: [req.validatedBody] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const price_list = await fetchPriceList( const price_list = await fetchPriceList(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -38,17 +38,12 @@ export const POST = async (
res: MedusaResponse res: MedusaResponse
) => { ) => {
const workflow = updatePricingRuleTypesWorkflow(req.scope) const workflow = updatePricingRuleTypesWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { input: {
data: [{ ...req.validatedBody, id: req.params.id }], data: [{ ...req.validatedBody, id: req.params.id }],
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const ruleType = await refetchRuleType( const ruleType = await refetchRuleType(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -67,15 +62,10 @@ export const DELETE = async (
const id = req.params.id const id = req.params.id
const workflow = deletePricingRuleTypesWorkflow(req.scope) const workflow = deletePricingRuleTypesWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "rule_type", object: "rule_type",
@@ -44,15 +44,10 @@ export const POST = async (
const workflow = createPricingRuleTypesWorkflow(req.scope) const workflow = createPricingRuleTypesWorkflow(req.scope)
const ruleTypesData = [req.validatedBody] const ruleTypesData = [req.validatedBody]
const { result, errors } = await workflow.run({ const { result } = await workflow.run({
input: { data: ruleTypesData }, input: { data: ruleTypesData },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const ruleType = await refetchRuleType( const ruleType = await refetchRuleType(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -15,15 +15,10 @@ export const POST = async (
) => { ) => {
const { id } = req.params const { id } = req.params
const { errors } = await batchLinkProductsToCategoryWorkflow(req.scope).run({ await batchLinkProductsToCategoryWorkflow(req.scope).run({
input: { id, ...req.validatedBody }, input: { id, ...req.validatedBody },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const category = await refetchEntity( const category = await refetchEntity(
"product_category", "product_category",
id, id,
@@ -31,15 +31,10 @@ export const POST = async (
const { id } = req.params const { id } = req.params
// TODO: Should be converted to bulk update // TODO: Should be converted to bulk update
const { errors } = await updateProductCategoryWorkflow(req.scope).run({ await updateProductCategoryWorkflow(req.scope).run({
input: { id, data: req.validatedBody }, input: { id, data: req.validatedBody },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const [category] = await refetchEntities( const [category] = await refetchEntities(
"product_category", "product_category",
{ id, ...req.filterableFields }, { id, ...req.filterableFields },
@@ -37,16 +37,9 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminCreateProductCategoryType>, req: AuthenticatedMedusaRequest<AdminCreateProductCategoryType>,
res: MedusaResponse<AdminProductCategoryResponse> res: MedusaResponse<AdminProductCategoryResponse>
) => { ) => {
const { result, errors } = await createProductCategoryWorkflow(req.scope).run( const { result } = await createProductCategoryWorkflow(req.scope).run({
{
input: { product_category: req.validatedBody }, input: { product_category: req.validatedBody },
throwOnError: false, })
}
)
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const [category] = await refetchEntities( const [category] = await refetchEntities(
"product_category", "product_category",
@@ -30,18 +30,13 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminUpdateProductTypeType>, req: AuthenticatedMedusaRequest<AdminUpdateProductTypeType>,
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { result, errors } = await updateProductTypesWorkflow(req.scope).run({ const { result } = await updateProductTypesWorkflow(req.scope).run({
input: { input: {
selector: { id: req.params.id }, selector: { id: req.params.id },
update: req.validatedBody, update: req.validatedBody,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const productType = await refetchProductType( const productType = await refetchProductType(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -57,15 +52,10 @@ export const DELETE = async (
) => { ) => {
const id = req.params.id const id = req.params.id
const { errors } = await deleteProductTypesWorkflow(req.scope).run({ await deleteProductTypesWorkflow(req.scope).run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "product_type", object: "product_type",
@@ -44,15 +44,10 @@ export const POST = async (
) => { ) => {
const input = [req.validatedBody] const input = [req.validatedBody]
const { result, errors } = await createProductTypesWorkflow(req.scope).run({ const { result } = await createProductTypesWorkflow(req.scope).run({
input: { product_types: input }, input: { product_types: input },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const productType = await refetchProductType( const productType = await refetchProductType(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -42,18 +42,13 @@ export const POST = async (
const productId = req.params.id const productId = req.params.id
const optionId = req.params.option_id const optionId = req.params.option_id
const { errors } = await updateProductOptionsWorkflow(req.scope).run({ await updateProductOptionsWorkflow(req.scope).run({
input: { input: {
selector: { id: optionId, product_id: productId }, selector: { id: optionId, product_id: productId },
update: req.validatedBody, update: req.validatedBody,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const product = await refetchProduct( const product = await refetchProduct(
productId, productId,
req.scope, req.scope,
@@ -70,15 +65,10 @@ export const DELETE = async (
const optionId = req.params.option_id const optionId = req.params.option_id
// TODO: I believe here we cannot even enforce the product ID based on the standard API we provide? // TODO: I believe here we cannot even enforce the product ID based on the standard API we provide?
const { errors } = await deleteProductOptionsWorkflow(req.scope).run({ await deleteProductOptionsWorkflow(req.scope).run({
input: { ids: [optionId] /* product_id: productId */ }, input: { ids: [optionId] /* product_id: productId */ },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const product = await refetchProduct( const product = await refetchProduct(
productId, productId,
req.scope, req.scope,
@@ -51,15 +51,10 @@ export const POST = async (
}, },
] ]
const { errors } = await createProductOptionsWorkflow(req.scope).run({ await createProductOptionsWorkflow(req.scope).run({
input: { product_options: input }, input: { product_options: input },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const product = await refetchProduct( const product = await refetchProduct(
productId, productId,
req.scope, req.scope,
@@ -43,18 +43,13 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminUpdateProductType>, req: AuthenticatedMedusaRequest<AdminUpdateProductType>,
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { result, errors } = await updateProductsWorkflow(req.scope).run({ const { result } = await updateProductsWorkflow(req.scope).run({
input: { input: {
selector: { id: req.params.id }, selector: { id: req.params.id },
update: req.validatedBody as UpdateProductDTO, update: req.validatedBody as UpdateProductDTO,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const product = await refetchProduct( const product = await refetchProduct(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -69,15 +64,10 @@ export const DELETE = async (
) => { ) => {
const id = req.params.id const id = req.params.id
const { errors } = await deleteProductsWorkflow(req.scope).run({ await deleteProductsWorkflow(req.scope).run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "product", object: "product",
@@ -49,18 +49,13 @@ export const POST = async (
const productId = req.params.id const productId = req.params.id
const variantId = req.params.variant_id const variantId = req.params.variant_id
const { errors } = await updateProductVariantsWorkflow(req.scope).run({ await updateProductVariantsWorkflow(req.scope).run({
input: { input: {
selector: { id: variantId, product_id: productId }, selector: { id: variantId, product_id: productId },
update: req.validatedBody, update: req.validatedBody,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const product = await refetchProduct( const product = await refetchProduct(
productId, productId,
req.scope, req.scope,
@@ -78,15 +73,10 @@ export const DELETE = async (
const variantId = req.params.variant_id const variantId = req.params.variant_id
// TODO: I believe here we cannot even enforce the product ID based on the standard API we provide? // TODO: I believe here we cannot even enforce the product ID based on the standard API we provide?
const { errors } = await deleteProductVariantsWorkflow(req.scope).run({ await deleteProductVariantsWorkflow(req.scope).run({
input: { ids: [variantId] /* product_id: productId */ }, input: { ids: [variantId] /* product_id: productId */ },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const product = await refetchProduct( const product = await refetchProduct(
productId, productId,
req.scope, req.scope,
@@ -34,15 +34,10 @@ export const POST = async (
// TODO: Fix types // TODO: Fix types
} as any } as any
const { result, errors } = await batchProductVariantsWorkflow(req.scope).run({ const { result } = await batchProductVariantsWorkflow(req.scope).run({
input: normalizedInput, input: normalizedInput,
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const batchResults = await refetchBatchVariants( const batchResults = await refetchBatchVariants(
result, result,
req.scope, req.scope,
@@ -56,15 +56,10 @@ export const POST = async (
}, },
] ]
const { errors } = await createProductVariantsWorkflow(req.scope).run({ await createProductVariantsWorkflow(req.scope).run({
input: { product_variants: input }, input: { product_variants: input },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const product = await refetchProduct( const product = await refetchProduct(
productId, productId,
req.scope, req.scope,
@@ -19,15 +19,10 @@ export const POST = async (
// TODO: Fix types // TODO: Fix types
const input = req.validatedBody as any const input = req.validatedBody as any
const { result, errors } = await batchProductsWorkflow(req.scope).run({ const { result } = await batchProductsWorkflow(req.scope).run({
input, input,
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const batchResults = await refetchBatchProducts( const batchResults = await refetchBatchProducts(
result, result,
req.scope, req.scope,
@@ -50,15 +50,10 @@ export const POST = async (
) => { ) => {
const input = [req.validatedBody as CreateProductDTO] const input = [req.validatedBody as CreateProductDTO]
const { result, errors } = await createProductsWorkflow(req.scope).run({ const { result } = await createProductsWorkflow(req.scope).run({
input: { products: input }, input: { products: input },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const product = await refetchProduct( const product = await refetchProduct(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -21,7 +21,7 @@ export const POST = async (
res: MedusaResponse res: MedusaResponse
) => { ) => {
const id = req.params.id const id = req.params.id
const { result, errors } = await batchPromotionRulesWorkflow(req.scope).run({ const { result } = await batchPromotionRulesWorkflow(req.scope).run({
input: { input: {
id, id,
rule_type: RuleType.BUY_RULES, rule_type: RuleType.BUY_RULES,
@@ -29,13 +29,8 @@ export const POST = async (
update: req.validatedBody.update, update: req.validatedBody.update,
delete: req.validatedBody.delete, delete: req.validatedBody.delete,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const batchResults = await refetchBatchRules( const batchResults = await refetchBatchRules(
result, result,
req.scope, req.scope,
@@ -54,15 +54,10 @@ export const POST = async (
} as any, } as any,
] ]
const { errors } = await updatePromotions.run({ await updatePromotions.run({
input: { promotionsData }, input: { promotionsData },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const promotion = await refetchPromotion( const promotion = await refetchPromotion(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -79,15 +74,10 @@ export const DELETE = async (
const id = req.params.id const id = req.params.id
const deletePromotions = deletePromotionsWorkflow(req.scope) const deletePromotions = deletePromotionsWorkflow(req.scope)
const { errors } = await deletePromotions.run({ await deletePromotions.run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "promotion", object: "promotion",
@@ -21,7 +21,7 @@ export const POST = async (
res: MedusaResponse res: MedusaResponse
) => { ) => {
const id = req.params.id const id = req.params.id
const { result, errors } = await batchPromotionRulesWorkflow(req.scope).run({ const { result } = await batchPromotionRulesWorkflow(req.scope).run({
input: { input: {
id, id,
rule_type: RuleType.RULES, rule_type: RuleType.RULES,
@@ -29,13 +29,8 @@ export const POST = async (
update: req.validatedBody.update, update: req.validatedBody.update,
delete: req.validatedBody.delete, delete: req.validatedBody.delete,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const batchResults = await refetchBatchRules( const batchResults = await refetchBatchRules(
result, result,
req.scope, req.scope,
@@ -21,7 +21,7 @@ export const POST = async (
res: MedusaResponse res: MedusaResponse
) => { ) => {
const id = req.params.id const id = req.params.id
const { result, errors } = await batchPromotionRulesWorkflow(req.scope).run({ const { result } = await batchPromotionRulesWorkflow(req.scope).run({
input: { input: {
id, id,
rule_type: RuleType.TARGET_RULES, rule_type: RuleType.TARGET_RULES,
@@ -29,13 +29,8 @@ export const POST = async (
update: req.validatedBody.update, update: req.validatedBody.update,
delete: req.validatedBody.delete, delete: req.validatedBody.delete,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const batchResults = await refetchBatchRules( const batchResults = await refetchBatchRules(
result, result,
req.scope, req.scope,
@@ -45,15 +45,10 @@ export const POST = async (
const createPromotions = createPromotionsWorkflow(req.scope) const createPromotions = createPromotionsWorkflow(req.scope)
const promotionsData = [req.validatedBody] as any const promotionsData = [req.validatedBody] as any
const { result, errors } = await createPromotions.run({ const { result } = await createPromotions.run({
input: { promotionsData }, input: { promotionsData },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const promotion = await refetchPromotion( const promotion = await refetchPromotion(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -25,18 +25,13 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminUpdateRegionType>, req: AuthenticatedMedusaRequest<AdminUpdateRegionType>,
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { result, errors } = await updateRegionsWorkflow(req.scope).run({ const { result } = await updateRegionsWorkflow(req.scope).run({
input: { input: {
selector: { id: req.params.id }, selector: { id: req.params.id },
update: req.validatedBody, update: req.validatedBody,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const region = await refetchRegion( const region = await refetchRegion(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -52,15 +47,10 @@ export const DELETE = async (
) => { ) => {
const id = req.params.id const id = req.params.id
const { errors } = await deleteRegionsWorkflow(req.scope).run({ await deleteRegionsWorkflow(req.scope).run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "region", object: "region",
@@ -41,15 +41,10 @@ export const POST = async (
) => { ) => {
const input = [req.validatedBody] const input = [req.validatedBody]
const { result, errors } = await createRegionsWorkflow(req.scope).run({ const { result } = await createRegionsWorkflow(req.scope).run({
input: { regions: input }, input: { regions: input },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const region = await refetchRegion( const region = await refetchRegion(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -38,17 +38,12 @@ export const POST = async (
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { id } = req.params const { id } = req.params
const { errors } = await updateReservationsWorkflow(req.scope).run({ await updateReservationsWorkflow(req.scope).run({
input: { input: {
updates: [{ ...req.validatedBody, id }], updates: [{ ...req.validatedBody, id }],
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const reservation = await refetchReservation( const reservation = await refetchReservation(
id, id,
req.scope, req.scope,
@@ -63,15 +58,10 @@ export const DELETE = async (
) => { ) => {
const id = req.params.id const id = req.params.id
const { errors } = await deleteReservationsWorkflow(req.scope).run({ await deleteReservationsWorkflow(req.scope).run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "reservation", object: "reservation",
@@ -45,15 +45,10 @@ export const POST = async (
) => { ) => {
const input = [req.validatedBody] const input = [req.validatedBody]
const { result, errors } = await createReservationsWorkflow(req.scope).run({ const { result } = await createReservationsWorkflow(req.scope).run({
input: { reservations: input }, input: { reservations: input },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const reservation = await refetchReservation( const reservation = await refetchReservation(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -43,11 +43,7 @@ export const POST = async (
update: req.validatedBody, update: req.validatedBody,
} }
const { result, errors } = await workflow.run({ input }) const { result } = await workflow.run({ input })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const variables = { id: result[0].id } const variables = { id: result[0].id }
@@ -50,11 +50,7 @@ export const POST = async (
], ],
} }
const { result, errors } = await workflow.run({ input }) const { result } = await workflow.run({ input })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const variables = { id: result[0].id } const variables = { id: result[0].id }
@@ -1,4 +1,4 @@
import { createReturnOrderWorkflow } from "@medusajs/core-flows" import {createReturnOrderWorkflow} from "@medusajs/core-flows"
import { import {
ContainerRegistrationKeys, ContainerRegistrationKeys,
remoteQueryObjectFromString, remoteQueryObjectFromString,
@@ -7,7 +7,7 @@ import {
AuthenticatedMedusaRequest, AuthenticatedMedusaRequest,
MedusaResponse, MedusaResponse,
} from "../../../types/routing" } from "../../../types/routing"
import { AdminPostReturnsReqSchemaType } from "./validators" import {AdminPostReturnsReqSchemaType} from "./validators"
export const GET = async ( export const GET = async (
req: AuthenticatedMedusaRequest, req: AuthenticatedMedusaRequest,
@@ -43,14 +43,9 @@ export const POST = async (
const input = req.validatedBody as AdminPostReturnsReqSchemaType const input = req.validatedBody as AdminPostReturnsReqSchemaType
const workflow = createReturnOrderWorkflow(req.scope) const workflow = createReturnOrderWorkflow(req.scope)
const { result, errors } = await workflow.run({ const { result } = await workflow.run({
input, input,
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ return: result }) res.status(200).json({ return: result })
} }
@@ -15,19 +15,14 @@ export const POST = async (
const { add, remove } = req.validatedBody const { add, remove } = req.validatedBody
const workflow = linkProductsToSalesChannelWorkflow(req.scope) const workflow = linkProductsToSalesChannelWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { input: {
id, id,
add, add,
remove, remove,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const salesChannel = await refetchSalesChannel( const salesChannel = await refetchSalesChannel(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -29,18 +29,13 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminUpdateSalesChannelType>, req: AuthenticatedMedusaRequest<AdminUpdateSalesChannelType>,
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { errors } = await updateSalesChannelsWorkflow(req.scope).run({ await updateSalesChannelsWorkflow(req.scope).run({
input: { input: {
selector: { id: req.params.id }, selector: { id: req.params.id },
update: req.validatedBody, update: req.validatedBody,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const salesChannel = await refetchSalesChannel( const salesChannel = await refetchSalesChannel(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -55,15 +50,10 @@ export const DELETE = async (
) => { ) => {
const id = req.params.id const id = req.params.id
const { errors } = await deleteSalesChannelsWorkflow(req.scope).run({ await deleteSalesChannelsWorkflow(req.scope).run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "sales-channel", object: "sales-channel",
@@ -44,15 +44,10 @@ export const POST = async (
) => { ) => {
const salesChannelsData = [req.validatedBody] const salesChannelsData = [req.validatedBody]
const { errors, result } = await createSalesChannelsWorkflow(req.scope).run({ const { result } = await createSalesChannelsWorkflow(req.scope).run({
input: { salesChannelsData }, input: { salesChannelsData },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const salesChannel = await refetchSalesChannel( const salesChannel = await refetchSalesChannel(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -28,15 +28,10 @@ export const POST = async (
...shippingOptionPayload, ...shippingOptionPayload,
} }
const { result, errors } = await workflow.run({ const { result } = await workflow.run({
input: [workflowInput], input: [workflowInput],
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const shippingOption = await refetchShippingOption( const shippingOption = await refetchShippingOption(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -54,15 +49,10 @@ export const DELETE = async (
const workflow = deleteShippingOptionsWorkflow(req.scope) const workflow = deleteShippingOptionsWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { ids: [shippingOptionId] }, input: { ids: [shippingOptionId] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res res
.status(200) .status(200)
.json({ id: shippingOptionId, object: "shipping_option", deleted: true }) .json({ id: shippingOptionId, object: "shipping_option", deleted: true })
@@ -20,9 +20,7 @@ export const POST = async (
res: MedusaResponse res: MedusaResponse
) => { ) => {
const id = req.params.id const id = req.params.id
const { result, errors } = await batchShippingOptionRulesWorkflow( const { result } = await batchShippingOptionRulesWorkflow(req.scope).run({
req.scope
).run({
input: { input: {
create: req.validatedBody.create?.map((c) => ({ create: req.validatedBody.create?.map((c) => ({
...c, ...c,
@@ -31,13 +29,8 @@ export const POST = async (
update: req.validatedBody.update, update: req.validatedBody.update,
delete: req.validatedBody.delete, delete: req.validatedBody.delete,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const batchResults = await refetchBatchRules( const batchResults = await refetchBatchRules(
result, result,
req.scope, req.scope,
@@ -50,15 +50,10 @@ export const POST = async (
const workflow = createShippingOptionsWorkflow(req.scope) const workflow = createShippingOptionsWorkflow(req.scope)
const { result, errors } = await workflow.run({ const { result } = await workflow.run({
input: [shippingOptionPayload], input: [shippingOptionPayload],
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const shippingOption = await refetchShippingOption( const shippingOption = await refetchShippingOption(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -38,15 +38,10 @@ export const DELETE = async (
// Test if exists // Test if exists
await fulfillmentModuleService.retrieveShippingProfile(id) await fulfillmentModuleService.retrieveShippingProfile(id)
const { errors } = await deleteShippingProfileWorkflow(req.scope).run({ await deleteShippingProfileWorkflow(req.scope).run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "shipping_profile", object: "shipping_profile",
@@ -23,17 +23,10 @@ export const POST = async (
) => { ) => {
const shippingProfilePayload = req.validatedBody const shippingProfilePayload = req.validatedBody
const { result, errors } = await createShippingProfilesWorkflow( const { result } = await createShippingProfilesWorkflow(req.scope).run({
req.scope
).run({
input: { data: [shippingProfilePayload] }, input: { data: [shippingProfilePayload] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const shippingProfile = await refetchShippingProfile( const shippingProfile = await refetchShippingProfile(
result?.[0].id, result?.[0].id,
req.scope, req.scope,
@@ -10,7 +10,7 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminCreateStockLocationFulfillmentSetType>, req: AuthenticatedMedusaRequest<AdminCreateStockLocationFulfillmentSetType>,
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { errors } = await createLocationFulfillmentSetWorkflow(req.scope).run({ await createLocationFulfillmentSetWorkflow(req.scope).run({
input: { input: {
location_id: req.params.id, location_id: req.params.id,
fulfillment_set_data: { fulfillment_set_data: {
@@ -18,13 +18,8 @@ export const POST = async (
type: req.validatedBody.type, type: req.validatedBody.type,
}, },
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const stockLocation = await refetchStockLocation( const stockLocation = await refetchStockLocation(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -65,15 +65,10 @@ export const DELETE = async (
) => { ) => {
const { id } = req.params const { id } = req.params
const { errors } = await deleteStockLocationsWorkflow(req.scope).run({ await deleteStockLocationsWorkflow(req.scope).run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "stock_location", object: "stock_location",
@@ -15,19 +15,14 @@ export const POST = async (
const { add, remove } = req.validatedBody const { add, remove } = req.validatedBody
const workflow = linkSalesChannelsToStockLocationWorkflow(req.scope) const workflow = linkSalesChannelsToStockLocationWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { input: {
id, id,
add, add,
remove, remove,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const stockLocation = await refetchStockLocation( const stockLocation = await refetchStockLocation(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -32,18 +32,13 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminUpdateStoreType>, req: AuthenticatedMedusaRequest<AdminUpdateStoreType>,
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { result, errors } = await updateStoresWorkflow(req.scope).run({ const { result } = await updateStoresWorkflow(req.scope).run({
input: { input: {
selector: { id: req.params.id }, selector: { id: req.params.id },
update: req.validatedBody as UpdateStoreDTO, update: req.validatedBody as UpdateStoreDTO,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const store = await refetchStore( const store = await refetchStore(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -20,18 +20,13 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminUpdateTaxRateType>, req: AuthenticatedMedusaRequest<AdminUpdateTaxRateType>,
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { errors } = await updateTaxRatesWorkflow(req.scope).run({ await updateTaxRatesWorkflow(req.scope).run({
input: { input: {
selector: { id: req.params.id }, selector: { id: req.params.id },
update: { ...req.validatedBody, updated_by: req.auth_context.actor_id }, update: { ...req.validatedBody, updated_by: req.auth_context.actor_id },
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const taxRate = await refetchTaxRate( const taxRate = await refetchTaxRate(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -62,15 +57,10 @@ export const DELETE = async (
res: MedusaResponse res: MedusaResponse
) => { ) => {
const id = req.params.id const id = req.params.id
const { errors } = await deleteTaxRatesWorkflow(req.scope).run({ await deleteTaxRatesWorkflow(req.scope).run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "tax_rate", object: "tax_rate",
@@ -9,15 +9,10 @@ export const DELETE = async (
req: AuthenticatedMedusaRequest, req: AuthenticatedMedusaRequest,
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { errors } = await deleteTaxRateRulesWorkflow(req.scope).run({ await deleteTaxRateRulesWorkflow(req.scope).run({
input: { ids: [req.params.rule_id] }, input: { ids: [req.params.rule_id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const taxRate = await refetchTaxRate( const taxRate = await refetchTaxRate(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -10,7 +10,7 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminCreateTaxRateRuleType>, req: AuthenticatedMedusaRequest<AdminCreateTaxRateRuleType>,
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { errors } = await createTaxRateRulesWorkflow(req.scope).run({ await createTaxRateRulesWorkflow(req.scope).run({
input: { input: {
rules: [ rules: [
{ {
@@ -20,13 +20,8 @@ export const POST = async (
}, },
], ],
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const taxRate = await refetchTaxRate( const taxRate = await refetchTaxRate(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -17,20 +17,15 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminCreateTaxRateType>, req: AuthenticatedMedusaRequest<AdminCreateTaxRateType>,
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { result, errors } = await createTaxRatesWorkflow(req.scope).run({ const { result } = await createTaxRatesWorkflow(req.scope).run({
input: [ input: [
{ {
...req.validatedBody, ...req.validatedBody,
created_by: req.auth_context.actor_id, created_by: req.auth_context.actor_id,
}, },
], ],
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const taxRate = await refetchTaxRate( const taxRate = await refetchTaxRate(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -32,15 +32,10 @@ export const DELETE = async (
) => { ) => {
const id = req.params.id const id = req.params.id
const { errors } = await deleteTaxRegionsWorkflow(req.scope).run({ await deleteTaxRegionsWorkflow(req.scope).run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "tax_region", object: "tax_region",
@@ -17,20 +17,15 @@ export const POST = async (
req: AuthenticatedMedusaRequest<AdminCreateTaxRegionType>, req: AuthenticatedMedusaRequest<AdminCreateTaxRegionType>,
res: MedusaResponse res: MedusaResponse
) => { ) => {
const { result, errors } = await createTaxRegionsWorkflow(req.scope).run({ const { result } = await createTaxRegionsWorkflow(req.scope).run({
input: [ input: [
{ {
...req.validatedBody, ...req.validatedBody,
created_by: req.auth_context.actor_id, created_by: req.auth_context.actor_id,
}, },
], ],
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const taxRegion = await refetchTaxRegion( const taxRegion = await refetchTaxRegion(
result[0].id, result[0].id,
req.scope, req.scope,
@@ -36,15 +36,10 @@ export const DELETE = async (
) => { ) => {
const id = req.params.id const id = req.params.id
const { errors } = await deleteFilesWorkflow(req.scope).run({ await deleteFilesWorkflow(req.scope).run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "file", object: "file",
@@ -19,7 +19,7 @@ export const POST = async (
) )
} }
const { result, errors } = await uploadFilesWorkflow(req.scope).run({ const { result } = await uploadFilesWorkflow(req.scope).run({
input: { input: {
files: input?.map((f) => ({ files: input?.map((f) => ({
filename: f.originalname, filename: f.originalname,
@@ -27,12 +27,7 @@ export const POST = async (
content: f.buffer.toString("binary"), content: f.buffer.toString("binary"),
})), })),
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ files: result }) res.status(200).json({ files: result })
} }
@@ -73,15 +73,10 @@ export const DELETE = async (
const { id } = req.params const { id } = req.params
const workflow = deleteUsersWorkflow(req.scope) const workflow = deleteUsersWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { ids: [id] }, input: { ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({ res.status(200).json({
id, id,
object: "user", object: "user",
+1 -8
View File
@@ -53,16 +53,9 @@ export const POST = async (
userData: req.validatedBody, userData: req.validatedBody,
authIdentityId: req.auth_context.auth_identity_id, authIdentityId: req.auth_context.auth_identity_id,
}, },
throwOnError: false,
} }
const { result, errors } = await createUserAccountWorkflow(req.scope).run( const { result } = await createUserAccountWorkflow(req.scope).run(input)
input
)
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const { http } = req.scope.resolve( const { http } = req.scope.resolve(
ContainerRegistrationKeys.CONFIG_MODULE ContainerRegistrationKeys.CONFIG_MODULE
@@ -28,7 +28,6 @@ export const POST = async (
context: { context: {
requestId: req.requestId, requestId: req.requestId,
}, },
throwOnError: false,
} as WorkflowOrchestratorTypes.WorkflowOrchestratorRunDTO } as WorkflowOrchestratorTypes.WorkflowOrchestratorRunDTO
const { acknowledgement } = await workflowEngineService.run( const { acknowledgement } = await workflowEngineService.run(
@@ -22,7 +22,7 @@ export const POST = async (
// When an error occurs on the workflow, its potentially got to with cart validations, payments // When an error occurs on the workflow, its potentially got to with cart validations, payments
// or inventory checks. Return the cart here along with errors for the consumer to take more action // or inventory checks. Return the cart here along with errors for the consumer to take more action
// and fix them // and fix them
if (Array.isArray(errors) && errors[0]) { if (errors?.[0]) {
const error = errors[0].error const error = errors[0].error
const statusOKErrors: string[] = [ const statusOKErrors: string[] = [
// TODO: add inventory specific errors // TODO: add inventory specific errors
@@ -45,15 +45,10 @@ export const POST = async (
update: req.validatedBody, update: req.validatedBody,
} }
const { errors } = await updateLineItemInCartWorkflow(req.scope).run({ await updateLineItemInCartWorkflow(req.scope).run({
input, input,
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const updatedCart = await refetchCart( const updatedCart = await refetchCart(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -69,15 +64,10 @@ export const DELETE = async (
) => { ) => {
const id = req.params.line_id const id = req.params.line_id
const { errors } = await deleteLineItemsWorkflow(req.scope).run({ await deleteLineItemsWorkflow(req.scope).run({
input: { cart_id: req.params.id, ids: [id] }, input: { cart_id: req.params.id, ids: [id] },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const cart = await refetchCart( const cart = await refetchCart(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -18,15 +18,10 @@ export const POST = async (
cart, cart,
} }
const { errors } = await addToCartWorkflow(req.scope).run({ await addToCartWorkflow(req.scope).run({
input: workflowInput, input: workflowInput,
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const updatedCart = await refetchCart( const updatedCart = await refetchCart(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -14,19 +14,14 @@ export const POST = async (
const workflow = updateCartPromotionsWorkflow(req.scope) const workflow = updateCartPromotionsWorkflow(req.scope)
const payload = req.validatedBody const payload = req.validatedBody
const { errors } = await workflow.run({ await workflow.run({
input: { input: {
promoCodes: payload.promo_codes, promoCodes: payload.promo_codes,
cartId: req.params.id, cartId: req.params.id,
action: PromotionActions.ADD, action: PromotionActions.ADD,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const cart = await refetchCart( const cart = await refetchCart(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -43,19 +38,14 @@ export const DELETE = async (
const workflow = updateCartPromotionsWorkflow(req.scope) const workflow = updateCartPromotionsWorkflow(req.scope)
const payload = req.validatedBody const payload = req.validatedBody
const { errors } = await workflow.run({ await workflow.run({
input: { input: {
promoCodes: payload.promo_codes, promoCodes: payload.promo_codes,
cartId: req.params.id, cartId: req.params.id,
action: PromotionActions.REMOVE, action: PromotionActions.REMOVE,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const cart = await refetchCart( const cart = await refetchCart(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -20,18 +20,13 @@ export const POST = async (
) => { ) => {
const workflow = updateCartWorkflow(req.scope) const workflow = updateCartWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { input: {
...(req.validatedBody as UpdateCartDataDTO), ...(req.validatedBody as UpdateCartDataDTO),
id: req.params.id, id: req.params.id,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const cart = await refetchCart( const cart = await refetchCart(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -10,18 +10,13 @@ export const POST = async (
const workflow = addShippingMethodToWorkflow(req.scope) const workflow = addShippingMethodToWorkflow(req.scope)
const payload = req.validatedBody const payload = req.validatedBody
const { errors } = await workflow.run({ await workflow.run({
input: { input: {
options: [{ id: payload.option_id, data: payload.data }], options: [{ id: payload.option_id, data: payload.data }],
cart_id: req.params.id, cart_id: req.params.id,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const cart = await refetchCart( const cart = await refetchCart(
req.params.id, req.params.id,
req.scope, req.scope,
@@ -9,18 +9,13 @@ export const POST = async (
) => { ) => {
const workflow = updateTaxLinesWorkflow(req.scope) const workflow = updateTaxLinesWorkflow(req.scope)
const { errors } = await workflow.run({ await workflow.run({
input: { input: {
cart_or_cart_id: req.params.id, cart_or_cart_id: req.params.id,
force_tax_calculation: true, force_tax_calculation: true,
}, },
throwOnError: false,
}) })
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const cart = await refetchCart( const cart = await refetchCart(
req.params.id, req.params.id,
req.scope, req.scope,
Loaded 100 of 109 files, more files were not shown because too many files have changed in this diff. Show more