feat(dashboard, core-flows): associate shipping option to type (#13226)
* feat(dashboard, core-flows): allow associating shipping option type to a shipping option * edit as well * fix translation schema * fix some tests * changeset * add new test to update shipping option type * add new test to create shipping option with shipping option type * pr comments * pr comments * rename variable * make zod great again
This commit is contained in:
@@ -4,12 +4,8 @@ import {
|
||||
ShippingOptionDTO,
|
||||
UpsertShippingOptionDTO,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
Modules,
|
||||
arrayDifference,
|
||||
getSelectsAndRelationsFromObjectArray,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
import { arrayDifference, getSelectsAndRelationsFromObjectArray, Modules, } from "@medusajs/framework/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The data to create or update shipping options.
|
||||
@@ -65,7 +61,13 @@ export const upsertShippingOptionsStep = createStep(
|
||||
|
||||
const upsertedShippingOptions: ShippingOptionDTO[] =
|
||||
await fulfillmentService.upsertShippingOptions(
|
||||
input as UpsertShippingOptionDTO[]
|
||||
input.map(inputItem => {
|
||||
const upsertShippingOption = inputItem as UpsertShippingOptionDTO
|
||||
if (inputItem.type_id) {
|
||||
upsertShippingOption.type = inputItem.type_id
|
||||
}
|
||||
return upsertShippingOption;
|
||||
})
|
||||
)
|
||||
|
||||
const upsertedShippingOptionIds = upsertedShippingOptions.map((s) => s.id)
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { FulfillmentWorkflow } from "@medusajs/framework/types"
|
||||
import {
|
||||
MedusaError,
|
||||
Modules,
|
||||
ShippingOptionPriceType,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
import { MedusaError, Modules, ShippingOptionPriceType, } from "@medusajs/framework/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
import { CreateShippingOptionDTO } from "@medusajs/types"
|
||||
|
||||
/**
|
||||
* The data to validate shipping option prices.
|
||||
@@ -96,7 +93,7 @@ export const validateShippingOptionPricesStep = createStep(
|
||||
|
||||
const validation =
|
||||
await fulfillmentModuleService.validateShippingOptionsForPriceCalculation(
|
||||
calculatedOptions as FulfillmentWorkflow.CreateShippingOptionsWorkflowInput[]
|
||||
calculatedOptions as CreateShippingOptionDTO[]
|
||||
)
|
||||
|
||||
if (validation.some((v) => !v)) {
|
||||
|
||||
@@ -6,10 +6,7 @@ import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import {
|
||||
createShippingOptionsPriceSetsStep,
|
||||
upsertShippingOptionsStep,
|
||||
} from "../steps"
|
||||
import { createShippingOptionsPriceSetsStep, upsertShippingOptionsStep, } from "../steps"
|
||||
import { setShippingOptionsPriceSetsStep } from "../steps/set-shipping-options-price-sets"
|
||||
import { validateFulfillmentProvidersStep } from "../steps/validate-fulfillment-providers"
|
||||
import { validateShippingOptionPricesStep } from "../steps/validate-shipping-option-prices"
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { z } from "zod"
|
||||
import { NextFunction } from "express"
|
||||
import { MedusaRequest, MedusaResponse } from "../types"
|
||||
import { zodValidator } from "../../zod/zod-helpers"
|
||||
import { zodValidator } from "../../zod"
|
||||
|
||||
export function validateAndTransformBody(
|
||||
zodSchema:
|
||||
| z.ZodObject<any, any>
|
||||
| z.ZodEffects<any, any>
|
||||
| ((
|
||||
customSchema?: z.ZodOptional<z.ZodNullable<z.ZodObject<any, any>>>
|
||||
) => z.ZodObject<any, any> | z.ZodEffects<any, any>)
|
||||
|
||||
@@ -35,7 +35,7 @@ export interface CreateShippingOptionDTO {
|
||||
/**
|
||||
* The shipping option type associated with the shipping option.
|
||||
*/
|
||||
type: CreateShippingOptionTypeDTO
|
||||
type: CreateShippingOptionTypeDTO | string
|
||||
|
||||
/**
|
||||
* The data necessary for the associated fulfillment provider to process the shipping option
|
||||
@@ -87,7 +87,7 @@ export interface UpdateShippingOptionDTO {
|
||||
* The shipping option type associated with the shipping option.
|
||||
*/
|
||||
type?:
|
||||
| Omit<CreateShippingOptionTypeDTO, "shipping_option_id">
|
||||
| CreateShippingOptionTypeDTO | string
|
||||
| {
|
||||
/**
|
||||
* The ID of the shipping option type.
|
||||
|
||||
@@ -156,7 +156,14 @@ export interface AdminCreateShippingOption {
|
||||
* Learn more in the [Shipping Option](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#shipping-profile-and-types)
|
||||
* documentation.
|
||||
*/
|
||||
type: AdminCreateShippingOptionType
|
||||
type?: AdminCreateShippingOptionType
|
||||
/**
|
||||
* The ID of the type of shipping option.
|
||||
*
|
||||
* Learn more in the [Shipping Option](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#shipping-profile-and-types)
|
||||
* documentation.
|
||||
*/
|
||||
type_id?: string
|
||||
/**
|
||||
* The prices of the shipping option.
|
||||
*/
|
||||
@@ -254,6 +261,13 @@ export interface AdminUpdateShippingOption {
|
||||
* documentation.
|
||||
*/
|
||||
type?: AdminCreateShippingOptionType
|
||||
/**
|
||||
* The ID of the type of shipping option.
|
||||
*
|
||||
* Learn more in the [Shipping Option](https://docs.medusajs.com/resources/commerce-modules/fulfillment/shipping-option#shipping-profile-and-types)
|
||||
* documentation.
|
||||
*/
|
||||
type_id?: string
|
||||
/**
|
||||
* The prices of the shipping option.
|
||||
*/
|
||||
|
||||
@@ -39,7 +39,7 @@ type CreateFlatShippingOptionInputBase = {
|
||||
/**
|
||||
* The type of the shipping option.
|
||||
*/
|
||||
type: {
|
||||
type?: {
|
||||
/**
|
||||
* The label of the shipping option type.
|
||||
*/
|
||||
@@ -53,6 +53,10 @@ type CreateFlatShippingOptionInputBase = {
|
||||
*/
|
||||
code: string
|
||||
}
|
||||
/**
|
||||
* The ID of the type of shipping option.
|
||||
*/
|
||||
type_id?: string
|
||||
/**
|
||||
* The rules that determine when the shipping option is available.
|
||||
*/
|
||||
|
||||
@@ -47,6 +47,10 @@ type UpdateFlatShippingOptionInputBase = {
|
||||
*/
|
||||
code: string
|
||||
}
|
||||
/**
|
||||
* The ID of the type of shipping option.
|
||||
*/
|
||||
type_id?: string
|
||||
/**
|
||||
* The rules that determine when the shipping option is available.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user