feat: inventory items api (#2971)

What:
Admin endpoints to handle inventory items and their stock levels per location

FIXES: CORE-975

Co-authored-by: Sebastian Rindom <7554214+srindom@users.noreply.github.com>
This commit is contained in:
Carlos R. L. Rodrigues
2023-01-23 12:06:23 +00:00
committed by GitHub
co-authored by Sebastian Rindom
parent 7152073b00
commit f65f590a27
21 changed files with 1671 additions and 15 deletions
@@ -0,0 +1,168 @@
import {
AdminGetInventoryItemsParams,
AdminInventoryItemsRes,
AdminPostInventoryItemsInventoryItemReq,
AdminGetInventoryItemsItemLocationLevelsParams,
AdminPostInventoryItemsItemLocationLevelsLevelReq,
AdminInventoryItemsDeleteRes,
AdminGetInventoryItemsItemParams,
AdminInventoryItemsListWithVariantsAndLocationLevelsRes,
AdminInventoryItemsLocationLevelsRes,
} from "@medusajs/medusa"
import { ResponsePromise } from "../../typings"
import BaseResource from "../base"
import qs from "qs"
class AdminInventoryItemsResource extends BaseResource {
/**
* Retrieve an Inventory Item
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/inventory
* @description gets an Inventory Item
* @returns an Inventory Item
*/
retrieve(
inventoryItemId: string,
query?: AdminGetInventoryItemsItemParams,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminInventoryItemsRes> {
let path = `/admin/inventory-items/${inventoryItemId}`
if (query) {
const queryString = qs.stringify(query)
path += `?${queryString}`
}
return this.client.request("GET", path, undefined, {}, customHeaders)
}
/**
* Update an Inventory Item
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/inventory
* @description updates an Inventory Item
* @returns the updated Inventory Item
*/
update(
inventoryItemId: string,
payload: AdminPostInventoryItemsInventoryItemReq,
query?: AdminGetInventoryItemsItemParams,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminInventoryItemsRes> {
let path = `/admin/inventory-items/${inventoryItemId}`
if (query) {
const queryString = qs.stringify(query)
path += `?${queryString}`
}
return this.client.request("POST", path, payload, {}, customHeaders)
}
/**
* Delete an Inventory Item
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/inventory
* @description deletes an Inventory Item
* @returns the deleted Inventory Item
*/
delete(
inventoryItemId: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminInventoryItemsDeleteRes> {
const path = `/admin/inventory-items/${inventoryItemId}`
return this.client.request("DELETE", path, undefined, {}, customHeaders)
}
/**
* Retrieve a list of Inventory Items
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/inventory
* @description Retrieve a list of Inventory Items
* @returns the list of Inventory Items as well as the pagination properties
*/
list(
query?: AdminGetInventoryItemsParams,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminInventoryItemsListWithVariantsAndLocationLevelsRes> {
let path = `/admin/inventory-items`
if (query) {
const queryString = qs.stringify(query)
path += `?${queryString}`
}
return this.client.request("GET", path, undefined, {}, customHeaders)
}
/**
* Update an Inventory Item's stock level at a Stock Location
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/inventory
* @description updates an Inventory Item
* @returns the updated Inventory Item
*/
updateLocationLevel(
inventoryItemId: string,
locationId: string,
payload: AdminPostInventoryItemsItemLocationLevelsLevelReq,
query?: AdminGetInventoryItemsParams,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminInventoryItemsRes> {
let path = `/admin/inventory-items/${inventoryItemId}/location-levels/${locationId}`
if (query) {
const queryString = qs.stringify(query)
path += `?${queryString}`
}
return this.client.request("POST", path, payload, {}, customHeaders)
}
/**
* Removes an Inventory Item from a Stock Location. This erases trace of any quantity currently at the location.
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/inventory
* @description deletes a location level of an Inventory Item
* @returns the Inventory Item
*/
deleteLocationLevel(
inventoryItemId: string,
locationId: string,
query?: AdminGetInventoryItemsParams,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminInventoryItemsRes> {
let path = `/admin/inventory-items/${inventoryItemId}/location-levels/${locationId}`
if (query) {
const queryString = qs.stringify(query)
path += `?${queryString}`
}
return this.client.request("DELETE", path, undefined, {}, customHeaders)
}
/**
* Retrieve a list of Inventory Levels related to an Inventory Item across Stock Locations
* @experimental This feature is under development and may change in the future.
* To use this feature please install @medusajs/inventory
* @description Retrieve a list of location levels related to an Inventory Item
* @returns the list of inventory levels related to an Inventory Item as well as the pagination properties
*/
listLocationLevels(
inventoryItemId: string,
query?: AdminGetInventoryItemsItemLocationLevelsParams,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminInventoryItemsLocationLevelsRes> {
let path = `/admin/inventory-items/${inventoryItemId}`
if (query) {
const queryString = qs.stringify(query)
path += `?${queryString}`
}
return this.client.request("GET", path, undefined, {}, customHeaders)
}
}
export default AdminInventoryItemsResource
@@ -4,17 +4,19 @@ import {
AdminPostStockLocationsLocationReq,
AdminPostStockLocationsReq,
AdminStockLocationsListRes,
AdminStockLocationsDeleteRes,
} from "@medusajs/medusa"
import { ResponsePromise } from "../../typings"
import BaseResource from "../base"
import qs from "qs"
class AdminStockLocationsResource extends BaseResource {
/** retrieve an stock location
/**
* Create a 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
* @description gets a medusa Stock Location
* @returns a medusa Stock Location
*/
create(
payload: AdminPostStockLocationsReq,
@@ -24,11 +26,12 @@ class AdminStockLocationsResource extends BaseResource {
return this.client.request("POST", path, payload, {}, customHeaders)
}
/** retrieve an stock location
/**
* Retrieve a 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
* @description gets a medusa Stock Location
* @returns a medusa Stock Location
*/
retrieve(
itemId: string,
@@ -38,11 +41,12 @@ class AdminStockLocationsResource extends BaseResource {
return this.client.request("GET", path, undefined, {}, customHeaders)
}
/** update an stock location
/**
* Update a 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
* @description updates a Stock Location
* @returns the updated medusa Stock Location
*/
update(
stockLocationId: string,
@@ -54,11 +58,25 @@ class AdminStockLocationsResource extends BaseResource {
}
/**
* Retrieve a list of stock locations
* Delete a Stock Location
* @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
* @description deletes a Stock Location
*/
delete(
id: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminStockLocationsDeleteRes> {
const path = `/admin/stock-locations/${id}`
return this.client.request("DELETE", path, undefined, {}, 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,