Skip to content

Commit

Permalink
fix product category service types
Browse files Browse the repository at this point in the history
adrien2p committed Nov 13, 2024
1 parent a6a02c2 commit 7c46858
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions packages/modules/product/src/services/product-category.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import {
Context,
DAL,
FindConfig,
InferEntityType,
ProductTypes,
} from "@medusajs/framework/types"
import {
@@ -33,15 +34,15 @@ export default class ProductCategoryService {
productCategoryId: string,
config: FindConfig<ProductTypes.ProductCategoryDTO> = {},
@MedusaContext() sharedContext: Context = {}
): Promise<typeof ProductCategory> {
): Promise<InferEntityType<typeof ProductCategory>> {
if (!isDefined(productCategoryId)) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`"productCategoryId" must be defined`
)
}

const queryOptions = ModulesSdkUtils.buildQuery<typeof ProductCategory>(
const queryOptions = ModulesSdkUtils.buildQuery(
{
id: productCategoryId,
},
@@ -67,15 +68,15 @@ export default class ProductCategoryService {
)
}

return productCategories[0] as typeof ProductCategory
return productCategories[0]
}

@InjectManager("productCategoryRepository_")
async list(
filters: ProductTypes.FilterableProductCategoryProps = {},
config: FindConfig<ProductTypes.ProductCategoryDTO> = {},
@MedusaContext() sharedContext: Context = {}
): Promise<(typeof ProductCategory)[]> {
): Promise<InferEntityType<typeof ProductCategory>[]> {
const transformOptions = {
includeDescendantsTree: filters?.include_descendants_tree || false,
includeAncestorsTree: filters?.include_ancestors_tree || false,
@@ -94,25 +95,22 @@ export default class ProductCategoryService {
delete filters.q
}

const queryOptions = ModulesSdkUtils.buildQuery<typeof ProductCategory>(
filters,
config
)
const queryOptions = ModulesSdkUtils.buildQuery(filters, config)
queryOptions.where ??= {}

return (await this.productCategoryRepository_.find(
return await this.productCategoryRepository_.find(
queryOptions,
transformOptions,
sharedContext
)) as (typeof ProductCategory)[]
)
}

@InjectManager("productCategoryRepository_")
async listAndCount(
filters: ProductTypes.FilterableProductCategoryProps = {},
config: FindConfig<ProductTypes.ProductCategoryDTO> = {},
@MedusaContext() sharedContext: Context = {}
): Promise<[(typeof ProductCategory)[], number]> {
): Promise<[InferEntityType<typeof ProductCategory>[], number]> {
const transformOptions = {
includeDescendantsTree: filters?.include_descendants_tree || false,
includeAncestorsTree: filters?.include_ancestors_tree || false,
@@ -131,37 +129,34 @@ export default class ProductCategoryService {
delete filters.q
}

const queryOptions = ModulesSdkUtils.buildQuery<typeof ProductCategory>(
filters,
config
)
const queryOptions = ModulesSdkUtils.buildQuery(filters, config)
queryOptions.where ??= {}

return (await this.productCategoryRepository_.findAndCount(
return await this.productCategoryRepository_.findAndCount(
queryOptions,
transformOptions,
sharedContext
)) as [(typeof ProductCategory)[], number]
)
}

@InjectTransactionManager("productCategoryRepository_")
async create(
data: ProductTypes.CreateProductCategoryDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<(typeof ProductCategory)[]> {
return (await (
): Promise<InferEntityType<typeof ProductCategory>[]> {
return await (
this.productCategoryRepository_ as unknown as ProductCategoryRepository
).create(data, sharedContext)) as (typeof ProductCategory)[]
).create(data, sharedContext)
}

@InjectTransactionManager("productCategoryRepository_")
async update(
data: UpdateCategoryInput[],
@MedusaContext() sharedContext: Context = {}
): Promise<(typeof ProductCategory)[]> {
return (await (
): Promise<InferEntityType<typeof ProductCategory>[]> {
return await (
this.productCategoryRepository_ as unknown as ProductCategoryRepository
).update(data, sharedContext)) as (typeof ProductCategory)[]
).update(data, sharedContext)
}

@InjectTransactionManager("productCategoryRepository_")

0 comments on commit 7c46858

Please sign in to comment.