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:
@@ -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"
|
||||
|
||||
@@ -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<void> => {
|
||||
.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 {}
|
||||
|
||||
@@ -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":
|
||||
|
||||
+13
-15
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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[]
|
||||
}
|
||||
|
||||
+11
-15
@@ -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":
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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"
|
||||
|
||||
+11
-16
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user