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
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa-js": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(medusa-js): added resources for product categories
|
||||||
@@ -337,7 +337,7 @@ describe("/admin/product-categories", () => {
|
|||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
expect(response.data.id).toEqual("invalid-id")
|
expect(response.data.id).toEqual("invalid-id")
|
||||||
expect(response.data.deleted).toBeTruthy()
|
expect(response.data.deleted).toBeTruthy()
|
||||||
expect(response.data.object).toEqual("product_category")
|
expect(response.data.object).toEqual("product-category")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("throws a not allowed error for a category with children", async () => {
|
it("throws a not allowed error for a category with children", async () => {
|
||||||
@@ -366,7 +366,7 @@ describe("/admin/product-categories", () => {
|
|||||||
expect(deleteResponse.status).toEqual(200)
|
expect(deleteResponse.status).toEqual(200)
|
||||||
expect(deleteResponse.data.id).toEqual(productCategory.id)
|
expect(deleteResponse.data.id).toEqual(productCategory.id)
|
||||||
expect(deleteResponse.data.deleted).toBeTruthy()
|
expect(deleteResponse.data.deleted).toBeTruthy()
|
||||||
expect(deleteResponse.data.object).toEqual("product_category")
|
expect(deleteResponse.data.object).toEqual("product-category")
|
||||||
|
|
||||||
const errorFetchingDeleted = await api.get(
|
const errorFetchingDeleted = await api.get(
|
||||||
`/admin/product-categories/${productCategory.id}`,
|
`/admin/product-categories/${productCategory.id}`,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import ReturnReasonsResource from "./resources/return-reasons"
|
|||||||
import ReturnsResource from "./resources/returns"
|
import ReturnsResource from "./resources/returns"
|
||||||
import ShippingOptionsResource from "./resources/shipping-options"
|
import ShippingOptionsResource from "./resources/shipping-options"
|
||||||
import SwapsResource from "./resources/swaps"
|
import SwapsResource from "./resources/swaps"
|
||||||
|
import ProductCategoriesResource from "./resources/product-categories"
|
||||||
|
|
||||||
class Medusa {
|
class Medusa {
|
||||||
private client: Client
|
private client: Client
|
||||||
@@ -42,6 +43,7 @@ class Medusa {
|
|||||||
public paymentMethods: PaymentMethodsResource
|
public paymentMethods: PaymentMethodsResource
|
||||||
public paymentCollections: PaymentCollectionsResource
|
public paymentCollections: PaymentCollectionsResource
|
||||||
public productTags: ProductTagsResource
|
public productTags: ProductTagsResource
|
||||||
|
public productCategories: ProductCategoriesResource
|
||||||
|
|
||||||
constructor(config: Config) {
|
constructor(config: Config) {
|
||||||
this.client = new Client(config)
|
this.client = new Client(config)
|
||||||
@@ -66,6 +68,7 @@ class Medusa {
|
|||||||
this.paymentMethods = new PaymentMethodsResource(this.client)
|
this.paymentMethods = new PaymentMethodsResource(this.client)
|
||||||
this.paymentCollections = new PaymentCollectionsResource(this.client)
|
this.paymentCollections = new PaymentCollectionsResource(this.client)
|
||||||
this.productTags = new ProductTagsResource(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 AdminVariantsResource from "./variants"
|
||||||
import AdminPaymentCollectionsResource from "./payment-collections"
|
import AdminPaymentCollectionsResource from "./payment-collections"
|
||||||
import AdminPaymentsResource from "./payments"
|
import AdminPaymentsResource from "./payments"
|
||||||
|
import AdminProductCategoriesResource from "./product-categories"
|
||||||
|
|
||||||
class Admin extends BaseResource {
|
class Admin extends BaseResource {
|
||||||
public auth = new AdminAuthResource(this.client)
|
public auth = new AdminAuthResource(this.client)
|
||||||
@@ -69,6 +70,7 @@ class Admin extends BaseResource {
|
|||||||
public uploads = new AdminUploadsResource(this.client)
|
public uploads = new AdminUploadsResource(this.client)
|
||||||
public paymentCollections = new AdminPaymentCollectionsResource(this.client)
|
public paymentCollections = new AdminPaymentCollectionsResource(this.client)
|
||||||
public payments = new AdminPaymentsResource(this.client)
|
public payments = new AdminPaymentsResource(this.client)
|
||||||
|
public productCategories = new AdminProductCategoriesResource(this.client)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Admin
|
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
|
||||||
@@ -35,6 +35,7 @@ export * from "./routes/admin/orders"
|
|||||||
export * from "./routes/admin/payment-collections"
|
export * from "./routes/admin/payment-collections"
|
||||||
export * from "./routes/admin/payments"
|
export * from "./routes/admin/payments"
|
||||||
export * from "./routes/admin/price-lists"
|
export * from "./routes/admin/price-lists"
|
||||||
|
export * from "./routes/admin/product-categories"
|
||||||
export * from "./routes/admin/product-tags"
|
export * from "./routes/admin/product-tags"
|
||||||
export * from "./routes/admin/product-types"
|
export * from "./routes/admin/product-types"
|
||||||
export * from "./routes/admin/products"
|
export * from "./routes/admin/products"
|
||||||
@@ -61,6 +62,7 @@ export * from "./routes/store/gift-cards"
|
|||||||
export * from "./routes/store/order-edits"
|
export * from "./routes/store/order-edits"
|
||||||
export * from "./routes/store/orders"
|
export * from "./routes/store/orders"
|
||||||
export * from "./routes/store/payment-collections"
|
export * from "./routes/store/payment-collections"
|
||||||
|
export * from "./routes/store/product-categories"
|
||||||
export * from "./routes/store/product-tags"
|
export * from "./routes/store/product-tags"
|
||||||
export * from "./routes/store/product-types"
|
export * from "./routes/store/product-types"
|
||||||
export * from "./routes/store/products"
|
export * from "./routes/store/products"
|
||||||
|
|||||||
@@ -24,7 +24,24 @@ import { FindParams } from "../../../../types/common"
|
|||||||
* $ref: "#/components/schemas/AdminPostProductCategoriesCategoryProductsBatchReq"
|
* $ref: "#/components/schemas/AdminPostProductCategoriesCategoryProductsBatchReq"
|
||||||
* x-codegen:
|
* x-codegen:
|
||||||
* method: addProducts
|
* method: addProducts
|
||||||
|
* queryParams: AdminPostProductCategoriesCategoryProductsBatchParams
|
||||||
* x-codeSamples:
|
* x-codeSamples:
|
||||||
|
* - lang: JavaScript
|
||||||
|
* label: JS Client
|
||||||
|
* source: |
|
||||||
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
|
* // must be previously logged in or use api token
|
||||||
|
* medusa.admin.productCategories.addProducts(product_category_id, {
|
||||||
|
* product_ids: [
|
||||||
|
* {
|
||||||
|
* id: product_id
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
* })
|
||||||
|
* .then(({ product_category }) => {
|
||||||
|
* console.log(product_category.id);
|
||||||
|
* });
|
||||||
* - lang: Shell
|
* - lang: Shell
|
||||||
* label: cURL
|
* label: cURL
|
||||||
* source: |
|
* source: |
|
||||||
@@ -50,7 +67,7 @@ import { FindParams } from "../../../../types/common"
|
|||||||
* content:
|
* content:
|
||||||
* application/json:
|
* application/json:
|
||||||
* schema:
|
* schema:
|
||||||
* $ref: "#/components/schemas/AdminProductCategoriesRes"
|
* $ref: "#/components/schemas/AdminProductCategoriesCategoryRes"
|
||||||
* "400":
|
* "400":
|
||||||
* $ref: "#/components/responses/400_error"
|
* $ref: "#/components/responses/400_error"
|
||||||
* "401":
|
* "401":
|
||||||
@@ -80,7 +97,7 @@ export default async (req: Request, res: Response): Promise<void> => {
|
|||||||
.withTransaction(transactionManager)
|
.withTransaction(transactionManager)
|
||||||
.addProducts(
|
.addProducts(
|
||||||
id,
|
id,
|
||||||
validatedBody.product_ids.map((p) => p.id),
|
validatedBody.product_ids.map((p) => p.id)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -117,4 +134,5 @@ export class AdminPostProductCategoriesCategoryProductsBatchReq {
|
|||||||
product_ids: ProductBatchProductCategory[]
|
product_ids: ProductBatchProductCategory[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
export class AdminPostProductCategoriesCategoryProductsBatchParams extends FindParams {}
|
export class AdminPostProductCategoriesCategoryProductsBatchParams extends FindParams {}
|
||||||
@@ -22,7 +22,20 @@ import { FindParams } from "../../../../types/common"
|
|||||||
* $ref: "#/components/schemas/AdminPostProductCategoriesReq"
|
* $ref: "#/components/schemas/AdminPostProductCategoriesReq"
|
||||||
* x-codegen:
|
* x-codegen:
|
||||||
* method: create
|
* method: create
|
||||||
|
* queryParams: AdminPostProductCategoriesParams
|
||||||
* x-codeSamples:
|
* x-codeSamples:
|
||||||
|
* - lang: JavaScript
|
||||||
|
* label: JS Client
|
||||||
|
* source: |
|
||||||
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
|
* // must be previously logged in or use api token
|
||||||
|
* medusa.admin.productCategories.create({
|
||||||
|
* name: 'App',
|
||||||
|
* })
|
||||||
|
* .then(({ product_category }) => {
|
||||||
|
* console.log(product_category.id);
|
||||||
|
* });
|
||||||
* - lang: Shell
|
* - lang: Shell
|
||||||
* label: cURL
|
* label: cURL
|
||||||
* source: |
|
* source: |
|
||||||
@@ -43,10 +56,7 @@ import { FindParams } from "../../../../types/common"
|
|||||||
* content:
|
* content:
|
||||||
* application/json:
|
* application/json:
|
||||||
* schema:
|
* schema:
|
||||||
* type: object
|
* $ref: "#/components/schemas/AdminProductCategoriesCategoryRes"
|
||||||
* properties:
|
|
||||||
* product_category:
|
|
||||||
* $ref: "#/components/schemas/ProductCategory"
|
|
||||||
* "400":
|
* "400":
|
||||||
* $ref: "#/components/responses/400_error"
|
* $ref: "#/components/responses/400_error"
|
||||||
* "401":
|
* "401":
|
||||||
|
|||||||
+13
-15
@@ -14,6 +14,16 @@ import { ProductCategoryService } from "../../../../services"
|
|||||||
* x-codegen:
|
* x-codegen:
|
||||||
* method: delete
|
* method: delete
|
||||||
* x-codeSamples:
|
* x-codeSamples:
|
||||||
|
* - lang: JavaScript
|
||||||
|
* label: JS Client
|
||||||
|
* source: |
|
||||||
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
|
* // must be previously logged in or use api token
|
||||||
|
* medusa.admin.productCategories.delete(product_category_id)
|
||||||
|
* .then(({ id, object, deleted }) => {
|
||||||
|
* console.log(id);
|
||||||
|
* });
|
||||||
* - lang: Shell
|
* - lang: Shell
|
||||||
* label: cURL
|
* label: cURL
|
||||||
* source: |
|
* source: |
|
||||||
@@ -25,24 +35,12 @@ import { ProductCategoryService } from "../../../../services"
|
|||||||
* tags:
|
* tags:
|
||||||
* - Product Category
|
* - Product Category
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* "200":
|
||||||
* description: OK
|
* description: OK
|
||||||
* content:
|
* content:
|
||||||
* application/json:
|
* application/json:
|
||||||
* schema:
|
* schema:
|
||||||
* type: object
|
* $ref: "#/components/schemas/AdminProductCategoriesCategoryDeleteRes"
|
||||||
* properties:
|
|
||||||
* id:
|
|
||||||
* type: string
|
|
||||||
* description: The ID of the deleted product category.
|
|
||||||
* object:
|
|
||||||
* type: string
|
|
||||||
* description: The type of the object that was deleted.
|
|
||||||
* default: product_category
|
|
||||||
* deleted:
|
|
||||||
* type: boolean
|
|
||||||
* description: Whether the product category was deleted successfully or not.
|
|
||||||
* default: true
|
|
||||||
* "400":
|
* "400":
|
||||||
* $ref: "#/components/responses/400_error"
|
* $ref: "#/components/responses/400_error"
|
||||||
* "401":
|
* "401":
|
||||||
@@ -74,7 +72,7 @@ export default async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
id: id,
|
id: id,
|
||||||
object: "product_category",
|
object: "product-category",
|
||||||
deleted: true,
|
deleted: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -26,6 +26,22 @@ import { FindParams } from "../../../../types/common"
|
|||||||
* method: removeProducts
|
* method: removeProducts
|
||||||
* queryParams: AdminDeleteProductCategoriesCategoryProductsBatchParams
|
* queryParams: AdminDeleteProductCategoriesCategoryProductsBatchParams
|
||||||
* x-codeSamples:
|
* x-codeSamples:
|
||||||
|
* - lang: JavaScript
|
||||||
|
* label: JS Client
|
||||||
|
* source: |
|
||||||
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
|
* // must be previously logged in or use api token
|
||||||
|
* medusa.admin.productCategories.removeProducts(product_category_id, {
|
||||||
|
* product_ids: [
|
||||||
|
* {
|
||||||
|
* id: product_id
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
* })
|
||||||
|
* .then(({ product_category }) => {
|
||||||
|
* console.log(product_category.id);
|
||||||
|
* });
|
||||||
* - lang: Shell
|
* - lang: Shell
|
||||||
* label: cURL
|
* label: cURL
|
||||||
* source: |
|
* source: |
|
||||||
@@ -45,12 +61,12 @@ import { FindParams } from "../../../../types/common"
|
|||||||
* tags:
|
* tags:
|
||||||
* - Product Category
|
* - Product Category
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* "200":
|
||||||
* description: OK
|
* description: OK
|
||||||
* content:
|
* content:
|
||||||
* application/json:
|
* application/json:
|
||||||
* schema:
|
* schema:
|
||||||
* $ref: "#/components/schemas/AdminProductCategoriesRes"
|
* $ref: "#/components/schemas/AdminProductCategoriesCategoryRes"
|
||||||
* "400":
|
* "400":
|
||||||
* $ref: "#/components/responses/400_error"
|
* $ref: "#/components/responses/400_error"
|
||||||
* "401":
|
* "401":
|
||||||
|
|||||||
@@ -18,6 +18,16 @@ import { defaultAdminProductCategoryRelations } from "."
|
|||||||
* method: retrieve
|
* method: retrieve
|
||||||
* queryParams: AdminGetProductCategoryParams
|
* queryParams: AdminGetProductCategoryParams
|
||||||
* x-codeSamples:
|
* x-codeSamples:
|
||||||
|
* - lang: JavaScript
|
||||||
|
* label: JS Client
|
||||||
|
* source: |
|
||||||
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
|
* // must be previously logged in or use api token
|
||||||
|
* medusa.admin.productCategories.retrieve(product_category_id)
|
||||||
|
* .then(({ product_category }) => {
|
||||||
|
* console.log(product_category.id);
|
||||||
|
* });
|
||||||
* - lang: Shell
|
* - lang: Shell
|
||||||
* label: cURL
|
* label: cURL
|
||||||
* source: |
|
* source: |
|
||||||
@@ -34,10 +44,7 @@ import { defaultAdminProductCategoryRelations } from "."
|
|||||||
* content:
|
* content:
|
||||||
* application/json:
|
* application/json:
|
||||||
* schema:
|
* schema:
|
||||||
* type: object
|
* $ref: "#/components/schemas/AdminProductCategoriesCategoryRes"
|
||||||
* properties:
|
|
||||||
* product_category:
|
|
||||||
* $ref: "#/components/schemas/ProductCategory"
|
|
||||||
* "400":
|
* "400":
|
||||||
* $ref: "#/components/responses/400_error"
|
* $ref: "#/components/responses/400_error"
|
||||||
* "401":
|
* "401":
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import middlewares, {
|
|||||||
transformBody,
|
transformBody,
|
||||||
} from "../../../middlewares"
|
} from "../../../middlewares"
|
||||||
|
|
||||||
|
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
|
||||||
import { isFeatureFlagEnabled } from "../../../middlewares/feature-flag-enabled"
|
import { isFeatureFlagEnabled } from "../../../middlewares/feature-flag-enabled"
|
||||||
import deleteProductCategory from "./delete-product-category"
|
import deleteProductCategory from "./delete-product-category"
|
||||||
import { validateProductsExist } from "../../../middlewares/validators/product-existence"
|
import { validateProductsExist } from "../../../middlewares/validators/product-existence"
|
||||||
@@ -123,6 +124,9 @@ export * from "./get-product-category"
|
|||||||
export * from "./delete-product-category"
|
export * from "./delete-product-category"
|
||||||
export * from "./list-product-categories"
|
export * from "./list-product-categories"
|
||||||
export * from "./create-product-category"
|
export * from "./create-product-category"
|
||||||
|
export * from "./update-product-category"
|
||||||
|
export * from "./add-products-batch"
|
||||||
|
export * from "./delete-products-batch"
|
||||||
|
|
||||||
export const defaultAdminProductCategoryRelations = [
|
export const defaultAdminProductCategoryRelations = [
|
||||||
"parent_category",
|
"parent_category",
|
||||||
@@ -145,12 +149,52 @@ export const defaultProductCategoryFields = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @schema AdminProductCategoriesRes
|
* @schema AdminProductCategoriesCategoryRes
|
||||||
* type: object
|
* type: object
|
||||||
* properties:
|
* properties:
|
||||||
* product_category:
|
* product_category:
|
||||||
* $ref: "#/components/schemas/ProductCategory"
|
* $ref: "#/components/schemas/ProductCategory"
|
||||||
*/
|
*/
|
||||||
export type AdminProductCategoriesRes = {
|
export type AdminProductCategoriesCategoryRes = {
|
||||||
product_category: ProductCategory
|
product_category: ProductCategory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @schema AdminProductCategoriesCategoryDeleteRes
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* id:
|
||||||
|
* type: string
|
||||||
|
* description: The ID of the deleted product category
|
||||||
|
* object:
|
||||||
|
* type: string
|
||||||
|
* description: The type of the object that was deleted.
|
||||||
|
* default: product-category
|
||||||
|
* deleted:
|
||||||
|
* type: boolean
|
||||||
|
* description: Whether or not the items were deleted.
|
||||||
|
* default: true
|
||||||
|
*/
|
||||||
|
export type AdminProductCategoriesCategoryDeleteRes = DeleteResponse
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @schema AdminProductCategoriesListRes
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* product_categories:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* $ref: "#/components/schemas/ProductCategory"
|
||||||
|
* count:
|
||||||
|
* type: integer
|
||||||
|
* description: The total number of items available
|
||||||
|
* offset:
|
||||||
|
* type: integer
|
||||||
|
* description: The number of items skipped before these items
|
||||||
|
* limit:
|
||||||
|
* type: integer
|
||||||
|
* description: The number of items per page
|
||||||
|
*/
|
||||||
|
export type AdminProductCategoriesListRes = PaginatedResponse & {
|
||||||
|
product_categories: ProductCategory[]
|
||||||
|
}
|
||||||
+11
-15
@@ -24,6 +24,16 @@ import { extendedFindParamsMixin } from "../../../../types/common"
|
|||||||
* method: list
|
* method: list
|
||||||
* queryParams: AdminGetProductCategoriesParams
|
* queryParams: AdminGetProductCategoriesParams
|
||||||
* x-codeSamples:
|
* x-codeSamples:
|
||||||
|
* - lang: JavaScript
|
||||||
|
* label: JS Client
|
||||||
|
* source: |
|
||||||
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
|
* // must be previously logged in or use api token
|
||||||
|
* medusa.admin.productCategories.list()
|
||||||
|
* .then(({ product_categories, limit, offset, count }) => {
|
||||||
|
* console.log(product_categories.length);
|
||||||
|
* });
|
||||||
* - lang: Shell
|
* - lang: Shell
|
||||||
* label: cURL
|
* label: cURL
|
||||||
* source: |
|
* source: |
|
||||||
@@ -40,21 +50,7 @@ import { extendedFindParamsMixin } from "../../../../types/common"
|
|||||||
* content:
|
* content:
|
||||||
* application/json:
|
* application/json:
|
||||||
* schema:
|
* schema:
|
||||||
* type: object
|
* $ref: "#/components/schemas/AdminProductCategoriesListRes"
|
||||||
* properties:
|
|
||||||
* product_categories:
|
|
||||||
* type: array
|
|
||||||
* items:
|
|
||||||
* $ref: "#/components/schemas/ProductCategory"
|
|
||||||
* count:
|
|
||||||
* type: integer
|
|
||||||
* description: The total number of items available
|
|
||||||
* offset:
|
|
||||||
* type: integer
|
|
||||||
* description: The number of items skipped before these items
|
|
||||||
* limit:
|
|
||||||
* type: integer
|
|
||||||
* description: The number of items per page
|
|
||||||
* "400":
|
* "400":
|
||||||
* $ref: "#/components/responses/400_error"
|
* $ref: "#/components/responses/400_error"
|
||||||
* "401":
|
* "401":
|
||||||
|
|||||||
@@ -25,6 +25,18 @@ import { FindParams } from "../../../../types/common"
|
|||||||
* method: update
|
* method: update
|
||||||
* queryParams: AdminPostProductCategoriesCategoryParams
|
* queryParams: AdminPostProductCategoriesCategoryParams
|
||||||
* x-codeSamples:
|
* x-codeSamples:
|
||||||
|
* - lang: JavaScript
|
||||||
|
* label: JS Client
|
||||||
|
* source: |
|
||||||
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
|
* // must be previously logged in or use api token
|
||||||
|
* medusa.admin.productCategories.update(product_category_id, {
|
||||||
|
* name: 'App'
|
||||||
|
* })
|
||||||
|
* .then(({ product_category }) => {
|
||||||
|
* console.log(product_category.id);
|
||||||
|
* });
|
||||||
* - lang: Shell
|
* - lang: Shell
|
||||||
* label: cURL
|
* label: cURL
|
||||||
* source: |
|
* source: |
|
||||||
@@ -45,10 +57,7 @@ import { FindParams } from "../../../../types/common"
|
|||||||
* content:
|
* content:
|
||||||
* application/json:
|
* application/json:
|
||||||
* schema:
|
* schema:
|
||||||
* type: object
|
* $ref: "#/components/schemas/AdminProductCategoriesCategoryRes"
|
||||||
* properties:
|
|
||||||
* product_category:
|
|
||||||
* $ref: "#/components/schemas/ProductCategory"
|
|
||||||
* "400":
|
* "400":
|
||||||
* $ref: "#/components/responses/400_error"
|
* $ref: "#/components/responses/400_error"
|
||||||
* "401":
|
* "401":
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import { defaultStoreScope } from "."
|
|||||||
* content:
|
* content:
|
||||||
* application/json:
|
* application/json:
|
||||||
* schema:
|
* schema:
|
||||||
* $ref: "#/components/schemas/StoreGetProductCategoryRes"
|
* $ref: "#/components/schemas/StoreGetProductCategoriesCategoryRes"
|
||||||
* "400":
|
* "400":
|
||||||
* $ref: "#/components/responses/400_error"
|
* $ref: "#/components/responses/400_error"
|
||||||
* "401":
|
* "401":
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
import { Router } from "express"
|
import { Router } from "express"
|
||||||
import middlewares, { transformQuery } from "../../../middlewares"
|
import middlewares, { transformQuery } from "../../../middlewares"
|
||||||
import getProductCategory, {
|
|
||||||
StoreGetProductCategoryParams,
|
|
||||||
} from "./get-product-category"
|
|
||||||
import { ProductCategory } from "../../../../models"
|
import { ProductCategory } from "../../../../models"
|
||||||
|
import { PaginatedResponse } from "../../../../types/common"
|
||||||
|
|
||||||
import listProductCategories, {
|
import listProductCategories, {
|
||||||
StoreGetProductCategoriesParams,
|
StoreGetProductCategoriesParams,
|
||||||
} from "./list-product-categories"
|
} from "./list-product-categories"
|
||||||
|
|
||||||
|
import getProductCategory, {
|
||||||
|
StoreGetProductCategoryParams,
|
||||||
|
} from "./get-product-category"
|
||||||
|
|
||||||
const route = Router()
|
const route = Router()
|
||||||
|
|
||||||
export default (app) => {
|
export default (app) => {
|
||||||
@@ -68,15 +70,37 @@ export const allowedStoreProductCategoryFields = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @schema StoreGetProductCategoryRes
|
* @schema StoreGetProductCategoriesCategoryRes
|
||||||
* type: object
|
* type: object
|
||||||
* properties:
|
* properties:
|
||||||
* product_category:
|
* product_category:
|
||||||
* $ref: "#/components/schemas/ProductCategory"
|
* $ref: "#/components/schemas/ProductCategory"
|
||||||
*/
|
*/
|
||||||
export type StoreGetProductCategoryRes = {
|
export type StoreGetProductCategoriesCategoryRes = {
|
||||||
product_category: ProductCategory
|
product_category: ProductCategory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @schema StoreProductCategoriesListRes
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* product_categories:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* $ref: "#/components/schemas/ProductCategory"
|
||||||
|
* count:
|
||||||
|
* type: integer
|
||||||
|
* description: The total number of items available
|
||||||
|
* offset:
|
||||||
|
* type: integer
|
||||||
|
* description: The number of items skipped before these items
|
||||||
|
* limit:
|
||||||
|
* type: integer
|
||||||
|
* description: The number of items per page
|
||||||
|
*/
|
||||||
|
export type StoreProductCategoriesListRes = PaginatedResponse & {
|
||||||
|
product_categories: ProductCategory[]
|
||||||
|
}
|
||||||
|
|
||||||
export * from "./get-product-category"
|
export * from "./get-product-category"
|
||||||
export * from "./list-product-categories"
|
export * from "./list-product-categories"
|
||||||
+11
-16
@@ -21,6 +21,15 @@ import { defaultStoreScope } from "."
|
|||||||
* method: list
|
* method: list
|
||||||
* queryParams: StoreGetProductCategoriesParams
|
* queryParams: StoreGetProductCategoriesParams
|
||||||
* x-codeSamples:
|
* x-codeSamples:
|
||||||
|
* - lang: JavaScript
|
||||||
|
* label: JS Client
|
||||||
|
* source: |
|
||||||
|
* import Medusa from "@medusajs/medusa-js"
|
||||||
|
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||||
|
* medusa.productCategories.list()
|
||||||
|
* .then(({ product_categories, limit, offset, count }) => {
|
||||||
|
* console.log(product_categories.length);
|
||||||
|
* });
|
||||||
* - lang: Shell
|
* - lang: Shell
|
||||||
* label: cURL
|
* label: cURL
|
||||||
* source: |
|
* source: |
|
||||||
@@ -32,26 +41,12 @@ import { defaultStoreScope } from "."
|
|||||||
* tags:
|
* tags:
|
||||||
* - Product Category
|
* - Product Category
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* "200":
|
||||||
* description: OK
|
* description: OK
|
||||||
* content:
|
* content:
|
||||||
* application/json:
|
* application/json:
|
||||||
* schema:
|
* schema:
|
||||||
* type: object
|
* $ref: "#/components/schemas/StoreProductCategoriesListRes"
|
||||||
* properties:
|
|
||||||
* product_categories:
|
|
||||||
* type: array
|
|
||||||
* items:
|
|
||||||
* $ref: "#/components/schemas/ProductCategory"
|
|
||||||
* count:
|
|
||||||
* type: integer
|
|
||||||
* description: The total number of items available
|
|
||||||
* offset:
|
|
||||||
* type: integer
|
|
||||||
* description: The number of items skipped before these items
|
|
||||||
* limit:
|
|
||||||
* type: integer
|
|
||||||
* description: The number of items per page
|
|
||||||
* "400":
|
* "400":
|
||||||
* $ref: "#/components/responses/400_error"
|
* $ref: "#/components/responses/400_error"
|
||||||
* "401":
|
* "401":
|
||||||
|
|||||||
Reference in new issue
Block a user