feat(dashboard,core-flows,medusa): update fulfillment flows (#7589)
* fix: fulfillment ops * fix: cancel fulfillment route * fix: adjustInventoryLevelsStep throwing * feat: cancel order and fix endpoint * fix: type * feat: order domain sdk * feat: delete unused file * fix: import
This commit is contained in:
1 parent
da3837f2bc
commit
d285e60961
26 files changed
+296
-183
No files matched your search
@@ -4,7 +4,7 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
type CancelOrderFulfillmentStepInput = CancelOrderFulfillmentDTO
|
||||
|
||||
export const cancelOrderFulfillmentStepId = "cancel-order-fullfillment"
|
||||
export const cancelOrderFulfillmentStepId = "cancel-order-fulfillment"
|
||||
export const cancelOrderFulfillmentStep = createStep(
|
||||
cancelOrderFulfillmentStepId,
|
||||
async (data: CancelOrderFulfillmentStepInput, { container }) => {
|
||||
|
||||
@@ -87,11 +87,14 @@ function prepareInventoryUpdate({
|
||||
}[] = []
|
||||
|
||||
for (const item of fulfillment.items) {
|
||||
inventoryAdjustment.push({
|
||||
inventory_item_id: item.inventory_item_id as string,
|
||||
location_id: fulfillment.location_id,
|
||||
adjustment: item.quantity,
|
||||
})
|
||||
// if this is `null` this means that item is from variant that has `manage_inventory` false
|
||||
if (item.inventory_item_id) {
|
||||
inventoryAdjustment.push({
|
||||
inventory_item_id: item.inventory_item_id as string,
|
||||
location_id: fulfillment.location_id,
|
||||
adjustment: item.quantity,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Product } from "./product"
|
||||
import { ProductCollection } from "./product-collection"
|
||||
import { Region } from "./region"
|
||||
import { Upload } from "./upload"
|
||||
import { Order } from "./order"
|
||||
|
||||
export class Admin {
|
||||
public invite: Invite
|
||||
@@ -13,6 +14,7 @@ export class Admin {
|
||||
public product: Product
|
||||
public upload: Upload
|
||||
public region: Region
|
||||
public order: Order
|
||||
|
||||
constructor(client: Client) {
|
||||
this.invite = new Invite(client)
|
||||
@@ -21,5 +23,6 @@ export class Admin {
|
||||
this.product = new Product(client)
|
||||
this.upload = new Upload(client)
|
||||
this.region = new Region(client)
|
||||
this.order = new Order(client)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import {
|
||||
AdminCancelOrderFulfillment,
|
||||
FindParams,
|
||||
HttpTypes,
|
||||
PaginatedResponse,
|
||||
SelectParams,
|
||||
} from "@medusajs/types"
|
||||
import { Client } from "../client"
|
||||
import { ClientHeaders } from "../types"
|
||||
|
||||
export class Order {
|
||||
private client: Client
|
||||
constructor(client: Client) {
|
||||
this.client = client
|
||||
}
|
||||
|
||||
async retrieve(id: string, query?: SelectParams, headers?: ClientHeaders) {
|
||||
return await this.client.fetch<{ order: HttpTypes.AdminOrder }>(
|
||||
`/admin/orders/${id}`,
|
||||
{
|
||||
query,
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async list(
|
||||
queryParams?: FindParams & HttpTypes.AdminOrderFilters,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<
|
||||
PaginatedResponse<{ orders: HttpTypes.AdminOrder[] }>
|
||||
>(`/admin/orders`, {
|
||||
query: queryParams,
|
||||
headers,
|
||||
})
|
||||
}
|
||||
|
||||
async cancel(id: string, headers?: ClientHeaders) {
|
||||
return await this.client.fetch<{ order: HttpTypes.AdminOrder }>(
|
||||
`/admin/orders/${id}/cancel`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async createFulfillment(
|
||||
id: string,
|
||||
body: HttpTypes.AdminCreateOrderFulfillment,
|
||||
query?: SelectParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<{ order: HttpTypes.AdminOrder }>(
|
||||
`/admin/orders/${id}/fulfillments`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async cancelFulfillment(
|
||||
id: string,
|
||||
fulfillmentId: string,
|
||||
body: HttpTypes.AdminCancelOrderFulfillment,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<{ order: HttpTypes.AdminOrder }>(
|
||||
`/admin/orders/${id}/fulfillments/${fulfillmentId}/cancel`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,24 @@
|
||||
import {
|
||||
BaseOrder,
|
||||
BaseOrderAddress,
|
||||
BaseOrderFilters,
|
||||
BaseOrderLineItem,
|
||||
BaseOrderShippingMethod,
|
||||
} from "./common"
|
||||
|
||||
export interface AdminOrder extends BaseOrder {}
|
||||
export interface AdminOrderLineItem extends BaseOrderLineItem {}
|
||||
export interface AdminOrderFilters extends BaseOrderFilters {}
|
||||
export interface AdminOrderAddress extends BaseOrderAddress {}
|
||||
export interface AdminOrderShippingMethod extends BaseOrderShippingMethod {}
|
||||
|
||||
export interface AdminCreateOrderFulfillment {
|
||||
items: { id: string; quantity: number }[]
|
||||
location_id?: string
|
||||
no_notification?: boolean
|
||||
metadata?: Record<string, any>
|
||||
}
|
||||
|
||||
export interface AdminCancelOrderFulfillment {
|
||||
no_notification?: boolean
|
||||
}
|
||||
@@ -1109,7 +1109,7 @@ export interface OrderDTO {
|
||||
raw_original_shipping_tax_total: BigNumberRawValue
|
||||
}
|
||||
|
||||
type PaymentStatus =
|
||||
export type PaymentStatus =
|
||||
| "not_paid"
|
||||
| "awaiting"
|
||||
| "authorized"
|
||||
@@ -1121,7 +1121,7 @@ type PaymentStatus =
|
||||
| "canceled"
|
||||
| "requires_action"
|
||||
|
||||
type FulfillmentStatus =
|
||||
export type FulfillmentStatus =
|
||||
| "not_fulfilled"
|
||||
| "partially_fulfilled"
|
||||
| "fulfilled"
|
||||
|
||||
Reference in new issue
Block a user