feat: Move shipping option + profile test and more (#7609)
This commit is contained in:
@@ -12,5 +12,7 @@ export * from "./delete-shipping-option-rules"
|
||||
export * from "./delete-shipping-options"
|
||||
export * from "./set-shipping-options-prices"
|
||||
export * from "./update-fulfillment"
|
||||
export * from "./update-shipping-profiles"
|
||||
export * from "./upsert-shipping-options"
|
||||
export * from "./validate-shipment"
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
FilterableShippingProfileProps,
|
||||
IFulfillmentModuleService,
|
||||
UpdateShippingProfileDTO,
|
||||
} from "@medusajs/types"
|
||||
import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
type StepInput = {
|
||||
update: UpdateShippingProfileDTO
|
||||
selector: FilterableShippingProfileProps
|
||||
}
|
||||
|
||||
export const updateShippingProfilesStepId = "update-shipping-profiles"
|
||||
export const updateShippingProfilesStep = createStep(
|
||||
updateShippingProfilesStepId,
|
||||
async (input: StepInput, { container }) => {
|
||||
const service = container.resolve<IFulfillmentModuleService>(
|
||||
ModuleRegistrationName.FULFILLMENT
|
||||
)
|
||||
|
||||
const { selects, relations } = getSelectsAndRelationsFromObjectArray([
|
||||
input.update,
|
||||
])
|
||||
|
||||
const prevData = await service.listShippingProfiles(input.selector, {
|
||||
select: selects,
|
||||
relations,
|
||||
})
|
||||
|
||||
const profiles = await service.updateShippingProfiles(
|
||||
input.selector,
|
||||
input.update
|
||||
)
|
||||
|
||||
return new StepResponse(profiles, prevData)
|
||||
},
|
||||
async (prevData, { container }) => {
|
||||
if (!prevData?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const service = container.resolve<IFulfillmentModuleService>(
|
||||
ModuleRegistrationName.FULFILLMENT
|
||||
)
|
||||
|
||||
await service.upsertShippingProfiles(prevData)
|
||||
}
|
||||
)
|
||||
@@ -12,3 +12,5 @@ export * from "./delete-shipping-options"
|
||||
export * from "./update-fulfillment"
|
||||
export * from "./update-service-zones"
|
||||
export * from "./update-shipping-options"
|
||||
export * from "./update-shipping-profiles"
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { FulfillmentWorkflow } from "@medusajs/types"
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { updateShippingProfilesStep } from "../steps/update-shipping-profiles"
|
||||
|
||||
export const updateShippingProfilesWorkflowId =
|
||||
"update-shipping-profiles-workflow"
|
||||
export const updateShippingProfilesWorkflow = createWorkflow(
|
||||
updateShippingProfilesWorkflowId,
|
||||
(
|
||||
input: WorkflowData<FulfillmentWorkflow.UpdateShippingProfilesWorkflowInput>
|
||||
): WorkflowData<FulfillmentWorkflow.CreateShippingProfilesWorkflowOutput> => {
|
||||
const shippingProfiles = updateShippingProfilesStep(input)
|
||||
|
||||
return shippingProfiles
|
||||
}
|
||||
)
|
||||
@@ -15,11 +15,32 @@ export interface CreateShippingProfileDTO {
|
||||
/**
|
||||
* Holds custom data in key-value pairs.
|
||||
*/
|
||||
metadata?: Record<string, unknown>
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
|
||||
/**
|
||||
* The attributes to update in the shipping profile.
|
||||
*/
|
||||
export interface UpdateShippingProfileDTO
|
||||
extends Partial<CreateShippingProfileDTO> {}
|
||||
export interface UpdateShippingProfileDTO {
|
||||
/**
|
||||
* The name of the shipping profile.
|
||||
*/
|
||||
name?: string
|
||||
|
||||
/**
|
||||
* The type of the shipping profile.
|
||||
*/
|
||||
type?: string
|
||||
|
||||
/**
|
||||
* Holds custom data in key-value pairs.
|
||||
*/
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
|
||||
/**
|
||||
* The attributes to update in the shipping profile.
|
||||
*/
|
||||
export interface UpsertShippingProfileDTO extends UpdateShippingProfileDTO {
|
||||
id?: string
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ import {
|
||||
UpsertShippingOptionDTO,
|
||||
} from "./mutations"
|
||||
import { CreateFulfillmentDTO } from "./mutations/fulfillment"
|
||||
import { CreateShippingProfileDTO } from "./mutations/shipping-profile"
|
||||
import { CreateShippingProfileDTO, UpsertShippingProfileDTO } from "./mutations/shipping-profile"
|
||||
|
||||
/**
|
||||
* The main service interface for the Fulfillment Module.
|
||||
@@ -1649,7 +1649,8 @@ export interface IFulfillmentModuleService extends IModuleService {
|
||||
/**
|
||||
* This method updates existing shipping profiles.
|
||||
*
|
||||
* @param {CreateShippingProfileDTO[]} data - The shipping profiles to be created.
|
||||
* @param {UpdateShippingProfileDTO} data - The shipping profiles update data.
|
||||
* @param {FilterableShippingProfileProps} selector - The selector of shipping profiles to update
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<ShippingProfileDTO[]>} The updated shipping profiles.
|
||||
*
|
||||
@@ -1667,14 +1668,16 @@ export interface IFulfillmentModuleService extends IModuleService {
|
||||
* ])
|
||||
*/
|
||||
updateShippingProfiles(
|
||||
data: UpdateShippingProfileDTO[],
|
||||
selector: FilterableShippingProfileProps,
|
||||
data: UpdateShippingProfileDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<ShippingProfileDTO[]>
|
||||
|
||||
/**
|
||||
* This method updates an existing shipping profiles.
|
||||
*
|
||||
* @param {CreateShippingProfileDTO} data - The shipping profile to be created.
|
||||
* @param {string} id - The shipping profile to be updated.
|
||||
* @param {UpdateShippingProfileDTO} data - The shipping profile to be created.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<ShippingProfileDTO>} The updated shipping profiles.
|
||||
*
|
||||
@@ -1686,6 +1689,7 @@ export interface IFulfillmentModuleService extends IModuleService {
|
||||
* })
|
||||
*/
|
||||
updateShippingProfiles(
|
||||
id: string,
|
||||
data: UpdateShippingProfileDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<ShippingProfileDTO>
|
||||
@@ -1719,6 +1723,51 @@ export interface IFulfillmentModuleService extends IModuleService {
|
||||
*/
|
||||
deleteShippingProfiles(id: string, sharedContext?: Context): Promise<void>
|
||||
|
||||
/**
|
||||
* This method updates existing shipping profiles, or creates new ones if they don't exist.
|
||||
*
|
||||
* @param {UpdateShippingProfileDTO[]} data - The attributes to update or create for each profile.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<ProductTagDTO[]>} The updated and created profiles.
|
||||
*
|
||||
* @example
|
||||
* const productTags = await productModuleService.upsertShippingProfiles([
|
||||
* {
|
||||
* id: "id_1234",
|
||||
* metadata: {
|
||||
* test: true,
|
||||
* },
|
||||
* },
|
||||
* {
|
||||
* name: "Digital",
|
||||
* },
|
||||
* ])
|
||||
*/
|
||||
upsertShippingProfiles(
|
||||
data: UpsertShippingProfileDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<ShippingProfileDTO[]>
|
||||
|
||||
/**
|
||||
* This method updates an existing shipping profile, or creates a new one if it doesn't exist.
|
||||
*
|
||||
* @param {UpdateShippingProfileDTO} data - The attributes to update or create for the profile.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<ProductTagDTO>} The updated or created profile.
|
||||
*
|
||||
* @example
|
||||
* const productTag = await productModuleService.upsertShippingProfiles({
|
||||
* id: "id_1234",
|
||||
* metadata: {
|
||||
* test: true,
|
||||
* },
|
||||
* })
|
||||
*/
|
||||
upsertShippingProfiles(
|
||||
data: UpsertShippingProfileDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<ShippingProfileDTO>
|
||||
|
||||
/**
|
||||
* This method soft deletes shipping profiles by their IDs.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user