feat(dashboard,js-sdk,types,admin-shared): Add Product Types domain (#7732)

This commit is contained in:
Kasper Fabricius Kristensen
2024-06-17 16:50:55 +00:00
committed by GitHub
parent 70a72ce2df
commit 2d8d2c4255
53 changed files with 1045 additions and 62 deletions
+3
View File
@@ -10,6 +10,7 @@ import { PriceList } from "./price-list"
import { Product } from "./product"
import { ProductCategory } from "./product-category"
import { ProductCollection } from "./product-collection"
import { ProductType } from "./product-type"
import { Region } from "./region"
import { SalesChannel } from "./sales-channel"
import { ShippingOption } from "./shipping-option"
@@ -26,6 +27,7 @@ export class Admin {
public productCategory: ProductCategory
public priceList: PriceList
public product: Product
public productType: ProductType
public upload: Upload
public region: Region
public stockLocation: StockLocation
@@ -47,6 +49,7 @@ export class Admin {
this.productCategory = new ProductCategory(client)
this.priceList = new PriceList(client)
this.product = new Product(client)
this.productType = new ProductType(client)
this.upload = new Upload(client)
this.region = new Region(client)
this.stockLocation = new StockLocation(client)
@@ -0,0 +1,80 @@
import { HttpTypes } from "@medusajs/types"
import { Client } from "../client"
import { ClientHeaders } from "../types"
export class ProductType {
private client: Client
constructor(client: Client) {
this.client = client
}
async create(
body: HttpTypes.AdminCreateProductType,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return this.client.fetch<HttpTypes.AdminProductTypeResponse>(
`/admin/product-types`,
{
method: "POST",
headers,
body,
query,
}
)
}
async update(
id: string,
body: HttpTypes.AdminUpdateProductType,
query?: HttpTypes.SelectParams,
headers?: ClientHeaders
) {
return this.client.fetch<HttpTypes.AdminProductTypeResponse>(
`/admin/product-types/${id}`,
{
method: "POST",
headers,
body,
query,
}
)
}
async list(
query?: HttpTypes.AdminProductTypeListParams,
headers?: ClientHeaders
) {
return this.client.fetch<HttpTypes.AdminProductTypeListResponse>(
`/admin/product-types`,
{
headers,
query: query,
}
)
}
async retrieve(
id: string,
query?: HttpTypes.AdminProductTypeParams,
headers?: ClientHeaders
) {
return this.client.fetch<HttpTypes.AdminProductTypeResponse>(
`/admin/product-types/${id}`,
{
query,
headers,
}
)
}
async delete(id: string, headers?: ClientHeaders) {
return this.client.fetch<HttpTypes.AdminProductTypeDeleteResponse>(
`/admin/product-types/${id}`,
{
method: "DELETE",
headers,
}
)
}
}
+1 -1
View File
@@ -55,7 +55,7 @@ export class Product {
)
}
async list(
queryParams?: HttpTypes.AdminProductParams,
queryParams?: HttpTypes.AdminProductListParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminProductListResponse>(
+1
View File
@@ -16,6 +16,7 @@ export * from "./payment"
export * from "./pricing"
export * from "./product"
export * from "./product-category"
export * from "./product-type"
export * from "./promotion"
export * from "./region"
export * from "./reservation"
@@ -0,0 +1,3 @@
import { BaseProductType } from "../common"
export interface AdminProductType extends BaseProductType {}
@@ -0,0 +1,4 @@
export * from "./entities"
export * from "./payloads"
export * from "./queries"
export * from "./responses"
@@ -0,0 +1,9 @@
export interface AdminCreateProductType {
value: string
metadata?: Record<string, unknown> | null
}
export interface AdminUpdateProductType {
value?: string
metadata?: Record<string, unknown> | null
}
@@ -0,0 +1,15 @@
import { BaseFilterable, OperatorMap } from "../../../dal"
import { FindParams, SelectParams } from "../../common"
export interface AdminProductTypeListParams
extends FindParams,
BaseFilterable<AdminProductTypeListParams> {
q?: string
id?: string | string[]
value?: string | string[]
created_at?: OperatorMap<string>
updated_at?: OperatorMap<string>
deleted_at?: OperatorMap<string>
}
export interface AdminProductTypeParams extends SelectParams {}
@@ -0,0 +1,14 @@
import { DeleteResponse, PaginatedResponse } from "../../common"
import { AdminProductType } from "./entities"
export interface AdminProductTypeResponse {
product_type: AdminProductType
}
export interface AdminProductTypeListResponse
extends PaginatedResponse<{
product_types: AdminProductType[]
}> {}
export interface AdminProductTypeDeleteResponse
extends DeleteResponse<"product_type"> {}
@@ -0,0 +1,8 @@
export interface BaseProductType {
id: string
value: string
created_at?: string
updated_at?: string
deleted_at?: string | null
metadata?: Record<string, unknown> | null
}
@@ -0,0 +1,2 @@
export * from "./admin"
export * from "./store"
@@ -0,0 +1,3 @@
import { BaseProductType } from "../common"
export interface StoreProductType extends BaseProductType {}
@@ -0,0 +1 @@
export * from "./entities"
@@ -1,5 +1,7 @@
import { AdminCollection } from "../../collection"
import { AdminPrice } from "../../pricing"
import { AdminProductCategory } from "../../product-category"
import { AdminProductType } from "../../product-type"
import { AdminSalesChannel } from "../../sales-channel"
import {
BaseProduct,
@@ -7,7 +9,6 @@ import {
BaseProductOption,
BaseProductOptionValue,
BaseProductTag,
BaseProductType,
BaseProductVariant,
ProductStatus,
} from "../common"
@@ -16,14 +17,15 @@ export interface AdminProductVariant extends BaseProductVariant {
prices: AdminPrice[] | null
}
export interface AdminProductTag extends BaseProductTag {}
export interface AdminProductType extends BaseProductType {}
export interface AdminProductOption extends BaseProductOption {}
export interface AdminProductImage extends BaseProductImage {}
export interface AdminProductOptionValue extends BaseProductOptionValue {}
export interface AdminProduct
extends Omit<BaseProduct, "categories" | "variants"> {
collection?: AdminCollection | null
categories?: AdminProductCategory[] | null
sales_channels?: AdminSalesChannel[] | null
variants?: AdminProductVariant[] | null
type: AdminProductType | null
}
export type AdminProductStatus = ProductStatus
@@ -1,16 +1,14 @@
import {
BaseProductListParams,
BaseProductOptionParams,
BaseProductParams,
BaseProductTagParams,
BaseProductTypeParams,
BaseProductVariantParams,
} from "../common"
export interface AdminProductTagParams extends BaseProductTagParams {}
export interface AdminProductTypeParams extends BaseProductTypeParams {}
export interface AdminProductOptionParams extends BaseProductOptionParams {}
export interface AdminProductVariantParams extends BaseProductVariantParams {}
export interface AdminProductParams extends BaseProductParams {
export interface AdminProductListParams extends BaseProductListParams {
price_list_id?: string | string[]
variants?: AdminProductVariantParams
}
+5 -21
View File
@@ -2,6 +2,7 @@ import { BaseFilterable, OperatorMap } from "../../dal"
import { BaseCollection } from "../collection/common"
import { FindParams } from "../common"
import { BaseProductCategory } from "../product-category/common"
import { BaseProductType } from "../product-type/common"
export type ProductStatus = "draft" | "proposed" | "published" | "rejected"
export interface BaseProduct {
@@ -21,10 +22,10 @@ export interface BaseProduct {
hs_code: string | null
mid_code: string | null
material: string | null
collection: BaseCollection | null
collection?: BaseCollection | null
collection_id: string | null
categories?: BaseProductCategory[] | null
type: BaseProductType | null
type?: BaseProductType | null
type_id: string | null
tags: BaseProductTag[] | null
variants: BaseProductVariant[] | null
@@ -72,15 +73,6 @@ export interface BaseProductTag {
metadata?: Record<string, unknown> | null
}
export interface BaseProductType {
id: string
value: string
created_at?: string
updated_at?: string
deleted_at?: string | null
metadata?: Record<string, unknown> | null
}
export interface BaseProductOption {
id: string
title: string
@@ -113,9 +105,9 @@ export interface BaseProductOptionValue {
deleted_at?: string | null
}
export interface BaseProductParams
export interface BaseProductListParams
extends FindParams,
BaseFilterable<BaseProductParams> {
BaseFilterable<BaseProductListParams> {
q?: string
status?: ProductStatus | ProductStatus[]
sales_channel_id?: string | string[]
@@ -143,14 +135,6 @@ export interface BaseProductTagParams
value?: string | string[]
}
export interface BaseProductTypeParams
extends FindParams,
BaseFilterable<BaseProductTypeParams> {
q?: string
id?: string | string[]
value?: string
}
export interface BaseProductOptionParams
extends FindParams,
BaseFilterable<BaseProductOptionParams> {
@@ -1,21 +1,21 @@
import { StoreProductCategory } from "../../product-category"
import { StoreProductType } from "../../product-type"
import {
BaseProduct,
BaseProductImage,
BaseProductOption,
BaseProductOptionValue,
BaseProductTag,
BaseProductType,
BaseProductVariant,
ProductStatus,
} from "../common"
export interface StoreProduct extends Omit<BaseProduct, "categories"> {
categories?: StoreProductCategory[] | null
type?: StoreProductType | null
}
export interface StoreProductVariant extends BaseProductVariant {}
export interface StoreProductTag extends BaseProductTag {}
export interface StoreProductType extends BaseProductType {}
export interface StoreProductOption extends BaseProductOption {}
export interface StoreProductImage extends BaseProductImage {}
export interface StoreProductOptionValue extends BaseProductOptionValue {}
@@ -1,16 +1,14 @@
import {
BaseProductListParams,
BaseProductOptionParams,
BaseProductParams,
BaseProductTagParams,
BaseProductTypeParams,
BaseProductVariantParams,
} from "../common"
export interface StoreProductTagParams extends BaseProductTagParams {}
export interface StoreProductTypeParams extends BaseProductTypeParams {}
export interface StoreProductOptionParams extends BaseProductOptionParams {}
export interface StoreProductVariantParams extends BaseProductVariantParams {}
export interface StoreProductParams extends BaseProductParams {
export interface StoreProductParams extends BaseProductListParams {
// The region ID and currency_code are not params, but are used for the pricing context. Maybe move to separate type definition.
region_id?: string
currency_code?: string