feat(medusa-js): added resources for product categories (#3157)
What: JS client resources for product categories Why: To manage product categories and managing product-category relationship How: - adds a JS client resource for product categories. RESOLVES CORE-1066 RESOLVES CORE-969 RESOLVES CORE-1061
This commit is contained in:
1 parent
4105405f28
commit
be0d36432a
18 files changed
+390
-72
No files matched your search
@@ -19,6 +19,7 @@ import ReturnReasonsResource from "./resources/return-reasons"
|
||||
import ReturnsResource from "./resources/returns"
|
||||
import ShippingOptionsResource from "./resources/shipping-options"
|
||||
import SwapsResource from "./resources/swaps"
|
||||
import ProductCategoriesResource from "./resources/product-categories"
|
||||
|
||||
class Medusa {
|
||||
private client: Client
|
||||
@@ -42,6 +43,7 @@ class Medusa {
|
||||
public paymentMethods: PaymentMethodsResource
|
||||
public paymentCollections: PaymentCollectionsResource
|
||||
public productTags: ProductTagsResource
|
||||
public productCategories: ProductCategoriesResource
|
||||
|
||||
constructor(config: Config) {
|
||||
this.client = new Client(config)
|
||||
@@ -66,6 +68,7 @@ class Medusa {
|
||||
this.paymentMethods = new PaymentMethodsResource(this.client)
|
||||
this.paymentCollections = new PaymentCollectionsResource(this.client)
|
||||
this.productTags = new ProductTagsResource(this.client)
|
||||
this.productCategories = new ProductCategoriesResource(this.client)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,6 +33,7 @@ import AdminUsersResource from "./users"
|
||||
import AdminVariantsResource from "./variants"
|
||||
import AdminPaymentCollectionsResource from "./payment-collections"
|
||||
import AdminPaymentsResource from "./payments"
|
||||
import AdminProductCategoriesResource from "./product-categories"
|
||||
|
||||
class Admin extends BaseResource {
|
||||
public auth = new AdminAuthResource(this.client)
|
||||
@@ -69,6 +70,7 @@ class Admin extends BaseResource {
|
||||
public uploads = new AdminUploadsResource(this.client)
|
||||
public paymentCollections = new AdminPaymentCollectionsResource(this.client)
|
||||
public payments = new AdminPaymentsResource(this.client)
|
||||
public productCategories = new AdminProductCategoriesResource(this.client)
|
||||
}
|
||||
|
||||
export default Admin
|
||||
@@ -0,0 +1,134 @@
|
||||
import {
|
||||
AdminDeleteProductCategoriesCategoryProductsBatchReq,
|
||||
AdminGetProductCategoriesParams,
|
||||
AdminPostProductCategoriesCategoryProductsBatchReq,
|
||||
AdminPostProductCategoriesReq,
|
||||
AdminPostProductCategoriesCategoryParams,
|
||||
AdminProductCategoriesCategoryDeleteRes,
|
||||
AdminProductCategoriesListRes,
|
||||
AdminProductCategoriesCategoryRes,
|
||||
AdminGetProductCategoryParams,
|
||||
} from "@medusajs/medusa"
|
||||
import qs from "qs"
|
||||
import { ResponsePromise } from "../../typings"
|
||||
import BaseResource from "../base"
|
||||
|
||||
class AdminProductCategoriesResource extends BaseResource {
|
||||
/** retrieve a product category
|
||||
* @experimental This feature is under development and may change in the future.
|
||||
* To use this feature please enable featureflag `product_categories` in your medusa backend project.
|
||||
* @description gets a product category
|
||||
* @returns a medusa product category
|
||||
*/
|
||||
retrieve(
|
||||
productCategoryId: string,
|
||||
query?: AdminGetProductCategoryParams,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<AdminProductCategoriesCategoryRes> {
|
||||
let path = `/admin/product-categories/${productCategoryId}`
|
||||
|
||||
if (query) {
|
||||
const queryString = qs.stringify(query)
|
||||
path = `${path}?${queryString}`
|
||||
}
|
||||
|
||||
return this.client.request("GET", path, undefined, {}, customHeaders)
|
||||
}
|
||||
|
||||
/* *
|
||||
* Create a medusa product category
|
||||
* @returns the created product category
|
||||
*/
|
||||
create(
|
||||
payload: AdminPostProductCategoriesReq,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<AdminProductCategoriesCategoryRes> {
|
||||
const path = `/admin/product-categories`
|
||||
return this.client.request("POST", path, payload, {}, customHeaders)
|
||||
}
|
||||
|
||||
/** update a product category
|
||||
* @experimental This feature is under development and may change in the future.
|
||||
* To use this feature please enable featureflag `product_categories` in your medusa backend project.
|
||||
* @description updates a product category
|
||||
* @returns the updated medusa product category
|
||||
*/
|
||||
update(
|
||||
productCategoryId: string,
|
||||
payload: AdminPostProductCategoriesCategoryParams,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<AdminProductCategoriesCategoryRes> {
|
||||
const path = `/admin/product-categories/${productCategoryId}`
|
||||
return this.client.request("POST", path, payload, {}, customHeaders)
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a list of product categorys
|
||||
* @experimental This feature is under development and may change in the future.
|
||||
* To use this feature please enable featureflag `product_categories` in your medusa backend project.
|
||||
* @description Retrieve a list of product categorys
|
||||
* @returns the list of product category as well as the pagination properties
|
||||
*/
|
||||
list(
|
||||
query?: AdminGetProductCategoriesParams,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<AdminProductCategoriesListRes> {
|
||||
let path = `/admin/product-categories`
|
||||
|
||||
if (query) {
|
||||
const queryString = qs.stringify(query)
|
||||
path += `?${queryString}`
|
||||
}
|
||||
|
||||
return this.client.request("GET", path, undefined, {}, customHeaders)
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a product category
|
||||
* @experimental This feature is under development and may change in the future.
|
||||
* To use this feature please enable featureflag `product_categories` in your medusa backend project.
|
||||
* @description gets a product category
|
||||
* @returns an deletion result
|
||||
*/
|
||||
delete(
|
||||
productCategoryId: string,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<AdminProductCategoriesCategoryDeleteRes> {
|
||||
const path = `/admin/product-categories/${productCategoryId}`
|
||||
return this.client.request("DELETE", path, undefined, {}, customHeaders)
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove products from a product category
|
||||
* @experimental This feature is under development and may change in the future.
|
||||
* To use this feature please enable featureflag `product_categories` in your medusa backend project.
|
||||
* @description Remove products from a product category
|
||||
* @returns a medusa product category
|
||||
*/
|
||||
removeProducts(
|
||||
productCategoryId: string,
|
||||
payload: AdminDeleteProductCategoriesCategoryProductsBatchReq,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<AdminProductCategoriesCategoryRes> {
|
||||
const path = `/admin/product-categories/${productCategoryId}/products/batch`
|
||||
return this.client.request("DELETE", path, payload, {}, customHeaders)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add products to a product category
|
||||
* @experimental This feature is under development and may change in the future.
|
||||
* To use this feature please enable featureflag `product_categories` in your medusa backend project.
|
||||
* @description Add products to a product category
|
||||
* @returns a medusa product category
|
||||
*/
|
||||
addProducts(
|
||||
productCategoryId: string,
|
||||
payload: AdminPostProductCategoriesCategoryProductsBatchReq,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<AdminProductCategoriesCategoryRes> {
|
||||
const path = `/admin/product-categories/${productCategoryId}/products/batch`
|
||||
return this.client.request("POST", path, payload, {}, customHeaders)
|
||||
}
|
||||
}
|
||||
|
||||
export default AdminProductCategoriesResource
|
||||
@@ -0,0 +1,55 @@
|
||||
import {
|
||||
StoreGetProductCategoriesCategoryRes,
|
||||
StoreProductCategoriesListRes,
|
||||
StoreGetProductCategoriesParams,
|
||||
StoreGetProductCategoryParams,
|
||||
} from "@medusajs/medusa"
|
||||
import qs from "qs"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import BaseResource from "./base"
|
||||
|
||||
class ProductCategoriesResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves a single product category
|
||||
* @param {string} id - id of the product category
|
||||
* @param {string} query is optional. Can contain a fields or relations for the returned list
|
||||
* @param customHeaders
|
||||
* @return {ResponsePromise<StoreGetProductCategoriesCategoryRes>}
|
||||
*/
|
||||
retrieve(
|
||||
id: string,
|
||||
query?: StoreGetProductCategoryParams,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<StoreGetProductCategoriesCategoryRes> {
|
||||
let path = `/store/product-categories/${id}`
|
||||
|
||||
if (query) {
|
||||
const queryString = qs.stringify(query)
|
||||
path = `${path}?${queryString}`
|
||||
}
|
||||
|
||||
return this.client.request("GET", path, undefined, {}, customHeaders)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Retrieves a list of product categories
|
||||
* @param {string} query is optional. Can contain a limit and offset for the returned list
|
||||
* @param customHeaders
|
||||
* @return {ResponsePromise<StoreProductCategoriesListRes>}
|
||||
*/
|
||||
list(
|
||||
query?: StoreGetProductCategoriesParams,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<StoreProductCategoriesListRes> {
|
||||
let path = `/store/product-categories`
|
||||
|
||||
if (query) {
|
||||
const queryString = qs.stringify(query)
|
||||
path = `${path}?${queryString}`
|
||||
}
|
||||
|
||||
return this.client.request("GET", path, undefined, {}, customHeaders)
|
||||
}
|
||||
}
|
||||
|
||||
export default ProductCategoriesResource
|
||||
Reference in new issue
Block a user