Adds DraftOrder Admin routes to JS client (#920)
This commit is contained in:
@@ -0,0 +1,116 @@
|
|||||||
|
import {
|
||||||
|
AdminDraftOrdersDeleteRes,
|
||||||
|
AdminDraftOrdersListRes,
|
||||||
|
AdminDraftOrdersRes,
|
||||||
|
AdminGetDraftOrdersParams,
|
||||||
|
AdminPostDraftOrdersDraftOrderLineItemsItemReq,
|
||||||
|
AdminPostDraftOrdersDraftOrderLineItemsReq,
|
||||||
|
AdminPostDraftOrdersDraftOrderRegisterPaymentRes,
|
||||||
|
AdminPostDraftOrdersDraftOrderReq,
|
||||||
|
} from "@medusajs/medusa"
|
||||||
|
import { ResponsePromise } from "../../typings"
|
||||||
|
import BaseResource from "../base"
|
||||||
|
|
||||||
|
class AdminDraftOrdersResource extends BaseResource {
|
||||||
|
/**
|
||||||
|
* @description Creates a draft order
|
||||||
|
*/
|
||||||
|
create(
|
||||||
|
payload: AdminPostDraftOrdersDraftOrderReq
|
||||||
|
): ResponsePromise<AdminDraftOrdersRes> {
|
||||||
|
const path = `/admin/draft-orders`
|
||||||
|
return this.client.request("POST", path, payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Add line item to draft order
|
||||||
|
*/
|
||||||
|
addLineItem(
|
||||||
|
id: string,
|
||||||
|
payload: AdminPostDraftOrdersDraftOrderLineItemsReq
|
||||||
|
): ResponsePromise<AdminDraftOrdersRes> {
|
||||||
|
const path = `/admin/draft-orders/${id}`
|
||||||
|
return this.client.request("POST", path, payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Delete draft order
|
||||||
|
*/
|
||||||
|
delete(id: string): ResponsePromise<AdminDraftOrdersDeleteRes> {
|
||||||
|
const path = `/admin/draft-orders/${id}`
|
||||||
|
return this.client.request("DELETE", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Remove line item
|
||||||
|
*/
|
||||||
|
removeLineItem(
|
||||||
|
id: string,
|
||||||
|
itemId: string
|
||||||
|
): ResponsePromise<AdminDraftOrdersRes> {
|
||||||
|
const path = `/admin/draft-orders/${id}/line-items/${itemId}`
|
||||||
|
return this.client.request("DELETE", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Retrieves a draft order
|
||||||
|
*/
|
||||||
|
retrieve(id: string): ResponsePromise<AdminDraftOrdersRes> {
|
||||||
|
const path = `/admin/draft-orders/${id}`
|
||||||
|
return this.client.request("GET", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Lists draft orders
|
||||||
|
*/
|
||||||
|
list(
|
||||||
|
query: AdminGetDraftOrdersParams
|
||||||
|
): ResponsePromise<AdminDraftOrdersListRes> {
|
||||||
|
let path = `/admin/draft-orders`
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
const queryString = Object.entries(query).map(([key, value]) => {
|
||||||
|
return `${key}=${value}`
|
||||||
|
})
|
||||||
|
|
||||||
|
path = `/admin/draft-orders?${queryString.join("&")}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.client.request("GET", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Mark a draft order as paid
|
||||||
|
*/
|
||||||
|
markPaid(
|
||||||
|
id: string
|
||||||
|
): ResponsePromise<AdminPostDraftOrdersDraftOrderRegisterPaymentRes> {
|
||||||
|
const path = `/admin/draft-orders/${id}/register-payment`
|
||||||
|
return this.client.request("POST", path, {})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Update draft order
|
||||||
|
*/
|
||||||
|
update(
|
||||||
|
id: string,
|
||||||
|
payload: AdminPostDraftOrdersDraftOrderReq
|
||||||
|
): ResponsePromise<AdminDraftOrdersRes> {
|
||||||
|
const path = `/admin/draft-orders/${id}`
|
||||||
|
return this.client.request("POST", path, payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Update draft order line item
|
||||||
|
*/
|
||||||
|
updateLineItem(
|
||||||
|
id: string,
|
||||||
|
itemId: string,
|
||||||
|
payload: AdminPostDraftOrdersDraftOrderLineItemsItemReq
|
||||||
|
): ResponsePromise<AdminDraftOrdersRes> {
|
||||||
|
const path = `/admin/draft-orders/${id}/line-items/${itemId}`
|
||||||
|
return this.client.request("POST", path, payload)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AdminDraftOrdersResource
|
||||||
@@ -17,6 +17,7 @@ export default (container, config) => {
|
|||||||
|
|
||||||
export * from "./routes/admin/auth"
|
export * from "./routes/admin/auth"
|
||||||
export * from "./routes/admin/customers"
|
export * from "./routes/admin/customers"
|
||||||
|
export * from "./routes/admin/draft-orders"
|
||||||
export * from "./routes/admin/discounts"
|
export * from "./routes/admin/discounts"
|
||||||
export * from "./routes/admin/notifications"
|
export * from "./routes/admin/notifications"
|
||||||
export * from "./routes/admin/store"
|
export * from "./routes/admin/store"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Router } from "express"
|
import { Router } from "express"
|
||||||
import { DraftOrder, Order, Cart } from "../../../.."
|
import { Cart, DraftOrder, Order } from "../../../.."
|
||||||
import middlewares from "../../../middlewares"
|
|
||||||
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
|
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
|
||||||
|
import middlewares from "../../../middlewares"
|
||||||
|
|
||||||
const route = Router()
|
const route = Router()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user