feat(medusa): Stock location module (#2907)

* feat: stock location module
This commit is contained in:
Carlos R. L. Rodrigues
2023-01-04 13:11:59 -03:00
committed by GitHub
parent cc10c20f35
commit c07ffb6165
50 changed files with 2040 additions and 198 deletions

View File

@@ -24,6 +24,7 @@ import AdminReturnsResource from "./returns"
import AdminSalesChannelsResource from "./sales-channels"
import AdminShippingOptionsResource from "./shipping-options"
import AdminShippingProfilesResource from "./shipping-profiles"
import AdminStockLocationsResource from "./stock-locations"
import AdminStoresResource from "./store"
import AdminSwapsResource from "./swaps"
import AdminTaxRatesResource from "./tax-rates"
@@ -59,6 +60,7 @@ class Admin extends BaseResource {
public salesChannels = new AdminSalesChannelsResource(this.client)
public swaps = new AdminSwapsResource(this.client)
public shippingProfiles = new AdminShippingProfilesResource(this.client)
public stockLocations = new AdminStockLocationsResource(this.client)
public store = new AdminStoresResource(this.client)
public shippingOptions = new AdminShippingOptionsResource(this.client)
public regions = new AdminRegionsResource(this.client)

View File

@@ -7,6 +7,8 @@ import {
AdminSalesChannelsListRes,
AdminDeleteSalesChannelsChannelProductsBatchReq,
AdminPostSalesChannelsChannelProductsBatchReq,
AdminPostSalesChannelsChannelStockLocationsReq,
AdminDeleteSalesChannelsChannelStockLocationsReq,
} from "@medusajs/medusa"
import { ResponsePromise } from "../../typings"
import BaseResource from "../base"
@@ -121,6 +123,38 @@ class AdminSalesChannelsResource extends BaseResource {
const path = `/admin/sales-channels/${salesChannelId}/products/batch`
return this.client.request("POST", path, payload, {}, customHeaders)
}
/**
* Add a location to a sales channel
* @experimental This feature is under development and may change in the future.
* To use this feature please enable featureflag `sales_channels` in your medusa backend project.
* @description Add a stock location to a SalesChannel
* @returns the Medusa SalesChannel
*/
addLocation(
salesChannelId: string,
payload: AdminPostSalesChannelsChannelStockLocationsReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminSalesChannelsRes> {
const path = `/admin/sales-channels/${salesChannelId}/stock-locations`
return this.client.request("POST", path, payload, {}, customHeaders)
}
/**
* remove a location from a sales channel
* @experimental This feature is under development and may change in the future.
* To use this feature please enable featureflag `sales_channels` in your medusa backend project.
* @description Remove a stock location from a SalesChannel
* @returns an deletion result
*/
removeLocation(
salesChannelId: string,
payload: AdminDeleteSalesChannelsChannelStockLocationsReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminSalesChannelsRes> {
const path = `/admin/sales-channels/${salesChannelId}/stock-locations`
return this.client.request("DELETE", path, payload, {}, customHeaders)
}
}
export default AdminSalesChannelsResource

View File

@@ -0,0 +1,78 @@
import {
AdminGetStockLocationsParams,
AdminStockLocationsRes,
AdminPostStockLocationsLocationReq,
AdminPostStockLocationsReq,
AdminStockLocationsListRes,
} from "@medusajs/medusa"
import { ResponsePromise } from "../../typings"
import BaseResource from "../base"
import qs from "qs"
class AdminStockLocationsResource extends BaseResource {
/** retrieve an stock location
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/stock-location
* @description gets a medusa stock location
* @returns a medusa stock location
*/
create(
payload: AdminPostStockLocationsReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminStockLocationsRes> {
const path = `/admin/stock-locations`
return this.client.request("POST", path, payload, {}, customHeaders)
}
/** retrieve an stock location
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/stock-location
* @description gets a medusa stock location
* @returns a medusa stock location
*/
retrieve(
itemId: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminStockLocationsRes> {
const path = `/admin/stock-locations/${itemId}`
return this.client.request("GET", path, undefined, {}, customHeaders)
}
/** update an stock location
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/stock-location
* @description updates an stock location
* @returns the updated medusa stock location
*/
update(
stockLocationId: string,
payload: AdminPostStockLocationsLocationReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminStockLocationsRes> {
const path = `/admin/stock-locations/${stockLocationId}`
return this.client.request("POST", path, payload, {}, customHeaders)
}
/**
* Retrieve a list of stock locations
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/stock-location
* @description Retrieve a list of stock locations
* @returns the list of stock locations as well as the pagination properties
*/
list(
query?: AdminGetStockLocationsParams,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminStockLocationsListRes> {
let path = `/admin/stock-locations`
if (query) {
const queryString = qs.stringify(query)
path += `?${queryString}`
}
return this.client.request("GET", path, undefined, {}, customHeaders)
}
}
export default AdminStockLocationsResource