feat: medusa js admin shipping options (#934)
* add: shipping-options admin endpoint to medusa-js * fix: retrieve return type for Collections * fix typo in routes Co-authored-by: Sebastian Rindom <seb@medusajs.com>
This commit is contained in:
1 parent
01b915585b
commit
8b1b551260
4 files changed
+85
-1
No files matched your search
@@ -51,7 +51,7 @@ class AdminCollectionsResource extends BaseResource {
|
|||||||
* @param id id of the collection to retrieve.
|
* @param id id of the collection to retrieve.
|
||||||
* @returns the collection with the given id
|
* @returns the collection with the given id
|
||||||
*/
|
*/
|
||||||
retrieve(id: string): ResponsePromise<AdminCollectionsListRes> {
|
retrieve(id: string): ResponsePromise<AdminCollectionsRes> {
|
||||||
const path = `/admin/collections/${id}`
|
const path = `/admin/collections/${id}`
|
||||||
return this.client.request("GET", path)
|
return this.client.request("GET", path)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import AdminReturnReasonsResource from "./return-reasons"
|
|||||||
import AdminVariantsResource from "./variants"
|
import AdminVariantsResource from "./variants"
|
||||||
import AdminSwapsResource from "./swaps"
|
import AdminSwapsResource from "./swaps"
|
||||||
import AdminShippingProfilesResource from "./shipping-profiles"
|
import AdminShippingProfilesResource from "./shipping-profiles"
|
||||||
|
import AdminShippingOptionsResource from "./shipping-options"
|
||||||
import AdminRegionsResource from "./regions"
|
import AdminRegionsResource from "./regions"
|
||||||
|
|
||||||
class Admin extends BaseResource {
|
class Admin extends BaseResource {
|
||||||
@@ -28,6 +29,7 @@ class Admin extends BaseResource {
|
|||||||
public variants = new AdminVariantsResource(this.client)
|
public variants = new AdminVariantsResource(this.client)
|
||||||
public swaps = new AdminSwapsResource(this.client)
|
public swaps = new AdminSwapsResource(this.client)
|
||||||
public shippingProfiles = new AdminShippingProfilesResource(this.client)
|
public shippingProfiles = new AdminShippingProfilesResource(this.client)
|
||||||
|
public shippingOptions = new AdminShippingOptionsResource(this.client)
|
||||||
public regions = new AdminRegionsResource(this.client)
|
public regions = new AdminRegionsResource(this.client)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
import {
|
||||||
|
AdminPostShippingOptionsReq,
|
||||||
|
AdminShippingOptionsRes,
|
||||||
|
AdminPostShippingOptionsOptionReq,
|
||||||
|
AdminShippingOptionsDeleteRes,
|
||||||
|
AdminShippingOptionsListRes,
|
||||||
|
AdminGetShippingOptionsParams,
|
||||||
|
} from "@medusajs/medusa"
|
||||||
|
import { ResponsePromise } from "../../typings"
|
||||||
|
import BaseResource from "../base"
|
||||||
|
|
||||||
|
class AdminShippingOptionsResource extends BaseResource {
|
||||||
|
/**
|
||||||
|
* @description creates a shipping option.
|
||||||
|
* @param payload
|
||||||
|
* @returns created shipping option.
|
||||||
|
*/
|
||||||
|
create(
|
||||||
|
payload: AdminPostShippingOptionsReq
|
||||||
|
): ResponsePromise<AdminShippingOptionsRes> {
|
||||||
|
const path = `/admin/shipping-options`
|
||||||
|
return this.client.request("POST", path, payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description updates a shipping option
|
||||||
|
* @param id id of the shipping option to update.
|
||||||
|
* @param payload update to apply to shipping option.
|
||||||
|
* @returns the updated shipping option.
|
||||||
|
*/
|
||||||
|
update(
|
||||||
|
id: string,
|
||||||
|
payload: AdminPostShippingOptionsOptionReq
|
||||||
|
): ResponsePromise<AdminShippingOptionsRes> {
|
||||||
|
const path = `/admin/shipping-options/${id}`
|
||||||
|
return this.client.request("POST", path, payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description deletes a shipping option
|
||||||
|
* @param id id of shipping option to delete.
|
||||||
|
* @returns deleted response
|
||||||
|
*/
|
||||||
|
delete(id: string): ResponsePromise<AdminShippingOptionsDeleteRes> {
|
||||||
|
const path = `/admin/shipping-options/${id}`
|
||||||
|
return this.client.request("DELETE", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description get a shipping option
|
||||||
|
* @param id id of the shipping option to retrieve.
|
||||||
|
* @returns the shipping option with the given id
|
||||||
|
*/
|
||||||
|
retrieve(id: string): ResponsePromise<AdminShippingOptionsRes> {
|
||||||
|
const path = `/admin/shipping-options/${id}`
|
||||||
|
return this.client.request("GET", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description lists shipping options matching a query
|
||||||
|
* @param query query for searching shipping options
|
||||||
|
* @returns a list of shipping options matching the query.
|
||||||
|
*/
|
||||||
|
list(
|
||||||
|
query?: AdminGetShippingOptionsParams
|
||||||
|
): ResponsePromise<AdminShippingOptionsListRes> {
|
||||||
|
let path = `/admin/shipping-options`
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
const queryString = Object.entries(query).map(([key, value]) => {
|
||||||
|
return typeof value !== "undefined" ? `${key}=${value}` : ""
|
||||||
|
})
|
||||||
|
path = `/admin/shipping-options?${queryString.join("&")}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.client.request("GET", path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AdminShippingOptionsResource
|
||||||
@@ -31,7 +31,9 @@ export * from "./routes/admin/orders"
|
|||||||
export * from "./routes/admin/variants"
|
export * from "./routes/admin/variants"
|
||||||
export * from "./routes/admin/return-reasons"
|
export * from "./routes/admin/return-reasons"
|
||||||
export * from "./routes/admin/swaps"
|
export * from "./routes/admin/swaps"
|
||||||
|
export * from "./routes/admin/shipping-options"
|
||||||
export * from "./routes/admin/regions"
|
export * from "./routes/admin/regions"
|
||||||
|
|
||||||
// Store
|
// Store
|
||||||
export * from "./routes/store/auth"
|
export * from "./routes/store/auth"
|
||||||
export * from "./routes/store/carts"
|
export * from "./routes/store/carts"
|
||||||
|
|||||||
Reference in new issue
Block a user