feat(medusa): Add inventory for variants (#2970)

* initial get-inventory impl

* add inventory management to create-variant

* update create-variant endpoint

* move if statement

* use middleware for module checking

* add endpoint to medusa-js

* export return type from get-inventory

* add jsdoc

* revert create variant

* rename variable

* initial setInventoryPattern for variant and product endpoints

* remove cache

* sort imports

* add sales channel info to inventory calculations

* add missing import

* remove promise.all from single promise

* update oas

* initial feedback

* checkout joinLevels from develop

* add variant middleware

* add comments
This commit is contained in:
Philip Korsholm authored and GitHub committed 2023-01-24 11:10:33 +01:00
1 parent 09dc9c6677
commit 8f4c84121b
13 files changed
+495 -17

No files matched your search

@@ -1,9 +1,19 @@
import { AdminGetVariantsParams, AdminVariantsListRes } from "@medusajs/medusa"
import {
AdminGetVariantsVariantInventoryRes,
AdminGetVariantsParams,
AdminVariantsListRes,
} from "@medusajs/medusa"
import qs from "qs"
import { ResponsePromise } from "../.."
import BaseResource from "../base"
class AdminVariantsResource extends BaseResource {
/**
* List product variants
* @param query Query to filter variants by
* @param customHeaders custom headers
* @returns A list of variants satisfying the criteria of the query
*/
list(
query?: AdminGetVariantsParams,
customHeaders: Record<string, any> = {}
@@ -17,6 +27,21 @@ class AdminVariantsResource extends BaseResource {
return this.client.request("GET", path, undefined, {}, customHeaders)
}
/**
*
* @param variantId id of the variant to fetch inventory for
* @param customHeaders custom headers
* @returns
*/
getInventory(
variantId: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminGetVariantsVariantInventoryRes> {
const path = `/admin/variants/${variantId}/inventory`
return this.client.request("GET", path, undefined, {}, customHeaders)
}
}
export default AdminVariantsResource