diff --git a/.changeset/swift-teachers-love.md b/.changeset/swift-teachers-love.md new file mode 100644 index 0000000000..1828bbaf89 --- /dev/null +++ b/.changeset/swift-teachers-love.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa-js": patch +--- + +feat(medusa-js): added resources for product categories diff --git a/integration-tests/api/__tests__/admin/product-category.ts b/integration-tests/api/__tests__/admin/product-category.ts index 0c26029361..0d9ceb3315 100644 --- a/integration-tests/api/__tests__/admin/product-category.ts +++ b/integration-tests/api/__tests__/admin/product-category.ts @@ -337,7 +337,7 @@ describe("/admin/product-categories", () => { expect(response.status).toEqual(200) expect(response.data.id).toEqual("invalid-id") 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 () => { @@ -366,7 +366,7 @@ describe("/admin/product-categories", () => { expect(deleteResponse.status).toEqual(200) expect(deleteResponse.data.id).toEqual(productCategory.id) expect(deleteResponse.data.deleted).toBeTruthy() - expect(deleteResponse.data.object).toEqual("product_category") + expect(deleteResponse.data.object).toEqual("product-category") const errorFetchingDeleted = await api.get( `/admin/product-categories/${productCategory.id}`, diff --git a/packages/medusa-js/src/index.ts b/packages/medusa-js/src/index.ts index 74c69af90e..389662c51d 100644 --- a/packages/medusa-js/src/index.ts +++ b/packages/medusa-js/src/index.ts @@ -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) } /** diff --git a/packages/medusa-js/src/resources/admin/index.ts b/packages/medusa-js/src/resources/admin/index.ts index 9d853b0567..1a116cc2c5 100644 --- a/packages/medusa-js/src/resources/admin/index.ts +++ b/packages/medusa-js/src/resources/admin/index.ts @@ -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 diff --git a/packages/medusa-js/src/resources/admin/product-categories.ts b/packages/medusa-js/src/resources/admin/product-categories.ts new file mode 100644 index 0000000000..36e534ffc1 --- /dev/null +++ b/packages/medusa-js/src/resources/admin/product-categories.ts @@ -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 = {} + ): ResponsePromise { + 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 = {} + ): ResponsePromise { + 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 = {} + ): ResponsePromise { + 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 = {} + ): ResponsePromise { + 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 = {} + ): ResponsePromise { + 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 = {} + ): ResponsePromise { + 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 = {} + ): ResponsePromise { + const path = `/admin/product-categories/${productCategoryId}/products/batch` + return this.client.request("POST", path, payload, {}, customHeaders) + } +} + +export default AdminProductCategoriesResource diff --git a/packages/medusa-js/src/resources/product-categories.ts b/packages/medusa-js/src/resources/product-categories.ts new file mode 100644 index 0000000000..2766a337ce --- /dev/null +++ b/packages/medusa-js/src/resources/product-categories.ts @@ -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} + */ + retrieve( + id: string, + query?: StoreGetProductCategoryParams, + customHeaders: Record = {} + ): ResponsePromise { + 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} + */ + list( + query?: StoreGetProductCategoriesParams, + customHeaders: Record = {} + ): ResponsePromise { + 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 diff --git a/packages/medusa/src/api/index.js b/packages/medusa/src/api/index.js index d4086f3a94..54c9efc06c 100644 --- a/packages/medusa/src/api/index.js +++ b/packages/medusa/src/api/index.js @@ -35,6 +35,7 @@ export * from "./routes/admin/orders" export * from "./routes/admin/payment-collections" export * from "./routes/admin/payments" export * from "./routes/admin/price-lists" +export * from "./routes/admin/product-categories" export * from "./routes/admin/product-tags" export * from "./routes/admin/product-types" 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/orders" export * from "./routes/store/payment-collections" +export * from "./routes/store/product-categories" export * from "./routes/store/product-tags" export * from "./routes/store/product-types" export * from "./routes/store/products" diff --git a/packages/medusa/src/api/routes/admin/product-categories/add-products-batch.ts b/packages/medusa/src/api/routes/admin/product-categories/add-products-batch.ts index 06b106318f..463d3b1118 100644 --- a/packages/medusa/src/api/routes/admin/product-categories/add-products-batch.ts +++ b/packages/medusa/src/api/routes/admin/product-categories/add-products-batch.ts @@ -24,7 +24,24 @@ import { FindParams } from "../../../../types/common" * $ref: "#/components/schemas/AdminPostProductCategoriesCategoryProductsBatchReq" * x-codegen: * method: addProducts + * queryParams: AdminPostProductCategoriesCategoryProductsBatchParams * 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 * label: cURL * source: | @@ -50,7 +67,7 @@ import { FindParams } from "../../../../types/common" * content: * application/json: * schema: - * $ref: "#/components/schemas/AdminProductCategoriesRes" + * $ref: "#/components/schemas/AdminProductCategoriesCategoryRes" * "400": * $ref: "#/components/responses/400_error" * "401": @@ -80,7 +97,7 @@ export default async (req: Request, res: Response): Promise => { .withTransaction(transactionManager) .addProducts( 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[] } +// eslint-disable-next-line max-len export class AdminPostProductCategoriesCategoryProductsBatchParams extends FindParams {} diff --git a/packages/medusa/src/api/routes/admin/product-categories/create-product-category.ts b/packages/medusa/src/api/routes/admin/product-categories/create-product-category.ts index f9596f86bb..e0e7bc55c5 100644 --- a/packages/medusa/src/api/routes/admin/product-categories/create-product-category.ts +++ b/packages/medusa/src/api/routes/admin/product-categories/create-product-category.ts @@ -22,7 +22,20 @@ import { FindParams } from "../../../../types/common" * $ref: "#/components/schemas/AdminPostProductCategoriesReq" * x-codegen: * method: create + * queryParams: AdminPostProductCategoriesParams * 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 * label: cURL * source: | @@ -43,10 +56,7 @@ import { FindParams } from "../../../../types/common" * content: * application/json: * schema: - * type: object - * properties: - * product_category: - * $ref: "#/components/schemas/ProductCategory" + * $ref: "#/components/schemas/AdminProductCategoriesCategoryRes" * "400": * $ref: "#/components/responses/400_error" * "401": diff --git a/packages/medusa/src/api/routes/admin/product-categories/delete-product-category.ts b/packages/medusa/src/api/routes/admin/product-categories/delete-product-category.ts index 087a741daf..ae62f0c7ea 100644 --- a/packages/medusa/src/api/routes/admin/product-categories/delete-product-category.ts +++ b/packages/medusa/src/api/routes/admin/product-categories/delete-product-category.ts @@ -14,6 +14,16 @@ import { ProductCategoryService } from "../../../../services" * x-codegen: * method: delete * 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 * label: cURL * source: | @@ -25,24 +35,12 @@ import { ProductCategoryService } from "../../../../services" * tags: * - Product Category * responses: - * 200: + * "200": * description: OK * content: * application/json: * schema: - * 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 the product category was deleted successfully or not. - * default: true + * $ref: "#/components/schemas/AdminProductCategoriesCategoryDeleteRes" * "400": * $ref: "#/components/responses/400_error" * "401": @@ -74,7 +72,7 @@ export default async (req: Request, res: Response) => { res.json({ id: id, - object: "product_category", + object: "product-category", deleted: true, }) } diff --git a/packages/medusa/src/api/routes/admin/product-categories/delete-products-batch.ts b/packages/medusa/src/api/routes/admin/product-categories/delete-products-batch.ts index f6db3712c7..95a05e78b1 100644 --- a/packages/medusa/src/api/routes/admin/product-categories/delete-products-batch.ts +++ b/packages/medusa/src/api/routes/admin/product-categories/delete-products-batch.ts @@ -26,6 +26,22 @@ import { FindParams } from "../../../../types/common" * method: removeProducts * queryParams: AdminDeleteProductCategoriesCategoryProductsBatchParams * 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 * label: cURL * source: | @@ -45,12 +61,12 @@ import { FindParams } from "../../../../types/common" * tags: * - Product Category * responses: - * 200: + * "200": * description: OK * content: * application/json: * schema: - * $ref: "#/components/schemas/AdminProductCategoriesRes" + * $ref: "#/components/schemas/AdminProductCategoriesCategoryRes" * "400": * $ref: "#/components/responses/400_error" * "401": diff --git a/packages/medusa/src/api/routes/admin/product-categories/get-product-category.ts b/packages/medusa/src/api/routes/admin/product-categories/get-product-category.ts index ca47b8d3c2..d7a8a75a7a 100644 --- a/packages/medusa/src/api/routes/admin/product-categories/get-product-category.ts +++ b/packages/medusa/src/api/routes/admin/product-categories/get-product-category.ts @@ -18,6 +18,16 @@ import { defaultAdminProductCategoryRelations } from "." * method: retrieve * queryParams: AdminGetProductCategoryParams * 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 * label: cURL * source: | @@ -34,10 +44,7 @@ import { defaultAdminProductCategoryRelations } from "." * content: * application/json: * schema: - * type: object - * properties: - * product_category: - * $ref: "#/components/schemas/ProductCategory" + * $ref: "#/components/schemas/AdminProductCategoriesCategoryRes" * "400": * $ref: "#/components/responses/400_error" * "401": diff --git a/packages/medusa/src/api/routes/admin/product-categories/index.ts b/packages/medusa/src/api/routes/admin/product-categories/index.ts index 5ad24f1f39..c487cf40ec 100644 --- a/packages/medusa/src/api/routes/admin/product-categories/index.ts +++ b/packages/medusa/src/api/routes/admin/product-categories/index.ts @@ -5,6 +5,7 @@ import middlewares, { transformBody, } from "../../../middlewares" +import { DeleteResponse, PaginatedResponse } from "../../../../types/common" import { isFeatureFlagEnabled } from "../../../middlewares/feature-flag-enabled" import deleteProductCategory from "./delete-product-category" import { validateProductsExist } from "../../../middlewares/validators/product-existence" @@ -123,6 +124,9 @@ export * from "./get-product-category" export * from "./delete-product-category" export * from "./list-product-categories" export * from "./create-product-category" +export * from "./update-product-category" +export * from "./add-products-batch" +export * from "./delete-products-batch" export const defaultAdminProductCategoryRelations = [ "parent_category", @@ -145,12 +149,52 @@ export const defaultProductCategoryFields = [ ] /** - * @schema AdminProductCategoriesRes + * @schema AdminProductCategoriesCategoryRes * type: object * properties: * product_category: * $ref: "#/components/schemas/ProductCategory" */ -export type AdminProductCategoriesRes = { +export type AdminProductCategoriesCategoryRes = { 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[] +} diff --git a/packages/medusa/src/api/routes/admin/product-categories/list-product-categories.ts b/packages/medusa/src/api/routes/admin/product-categories/list-product-categories.ts index c48a10d0ad..d357458074 100644 --- a/packages/medusa/src/api/routes/admin/product-categories/list-product-categories.ts +++ b/packages/medusa/src/api/routes/admin/product-categories/list-product-categories.ts @@ -24,6 +24,16 @@ import { extendedFindParamsMixin } from "../../../../types/common" * method: list * queryParams: AdminGetProductCategoriesParams * 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 * label: cURL * source: | @@ -40,21 +50,7 @@ import { extendedFindParamsMixin } from "../../../../types/common" * content: * application/json: * schema: - * 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 + * $ref: "#/components/schemas/AdminProductCategoriesListRes" * "400": * $ref: "#/components/responses/400_error" * "401": diff --git a/packages/medusa/src/api/routes/admin/product-categories/update-product-category.ts b/packages/medusa/src/api/routes/admin/product-categories/update-product-category.ts index 0199620e30..6045b05481 100644 --- a/packages/medusa/src/api/routes/admin/product-categories/update-product-category.ts +++ b/packages/medusa/src/api/routes/admin/product-categories/update-product-category.ts @@ -25,6 +25,18 @@ import { FindParams } from "../../../../types/common" * method: update * queryParams: AdminPostProductCategoriesCategoryParams * 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 * label: cURL * source: | @@ -45,10 +57,7 @@ import { FindParams } from "../../../../types/common" * content: * application/json: * schema: - * type: object - * properties: - * product_category: - * $ref: "#/components/schemas/ProductCategory" + * $ref: "#/components/schemas/AdminProductCategoriesCategoryRes" * "400": * $ref: "#/components/responses/400_error" * "401": diff --git a/packages/medusa/src/api/routes/store/product-categories/get-product-category.ts b/packages/medusa/src/api/routes/store/product-categories/get-product-category.ts index a8edb48304..3440d8981a 100644 --- a/packages/medusa/src/api/routes/store/product-categories/get-product-category.ts +++ b/packages/medusa/src/api/routes/store/product-categories/get-product-category.ts @@ -45,7 +45,7 @@ import { defaultStoreScope } from "." * content: * application/json: * schema: - * $ref: "#/components/schemas/StoreGetProductCategoryRes" + * $ref: "#/components/schemas/StoreGetProductCategoriesCategoryRes" * "400": * $ref: "#/components/responses/400_error" * "401": diff --git a/packages/medusa/src/api/routes/store/product-categories/index.ts b/packages/medusa/src/api/routes/store/product-categories/index.ts index 99ce350044..6b75789879 100644 --- a/packages/medusa/src/api/routes/store/product-categories/index.ts +++ b/packages/medusa/src/api/routes/store/product-categories/index.ts @@ -1,14 +1,16 @@ import { Router } from "express" import middlewares, { transformQuery } from "../../../middlewares" -import getProductCategory, { - StoreGetProductCategoryParams, -} from "./get-product-category" import { ProductCategory } from "../../../../models" +import { PaginatedResponse } from "../../../../types/common" import listProductCategories, { StoreGetProductCategoriesParams, } from "./list-product-categories" +import getProductCategory, { + StoreGetProductCategoryParams, +} from "./get-product-category" + const route = Router() export default (app) => { @@ -68,15 +70,37 @@ export const allowedStoreProductCategoryFields = [ ] /** - * @schema StoreGetProductCategoryRes + * @schema StoreGetProductCategoriesCategoryRes * type: object * properties: * product_category: * $ref: "#/components/schemas/ProductCategory" */ -export type StoreGetProductCategoryRes = { +export type StoreGetProductCategoriesCategoryRes = { 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 "./list-product-categories" diff --git a/packages/medusa/src/api/routes/store/product-categories/list-product-categories.ts b/packages/medusa/src/api/routes/store/product-categories/list-product-categories.ts index 615a70777f..3d87030063 100644 --- a/packages/medusa/src/api/routes/store/product-categories/list-product-categories.ts +++ b/packages/medusa/src/api/routes/store/product-categories/list-product-categories.ts @@ -21,6 +21,15 @@ import { defaultStoreScope } from "." * method: list * queryParams: StoreGetProductCategoriesParams * 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 * label: cURL * source: | @@ -32,26 +41,12 @@ import { defaultStoreScope } from "." * tags: * - Product Category * responses: - * 200: + * "200": * description: OK * content: * application/json: * schema: - * 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 + * $ref: "#/components/schemas/StoreProductCategoriesListRes" * "400": * $ref: "#/components/responses/400_error" * "401":