chore: Internal medusa service proper typings with DML (#7792)
This commit is contained in:
committed by
GitHub
parent
944051a951
commit
90e6ca0e9e
@@ -15,9 +15,7 @@ import { UpdateCategoryInput } from "@types"
|
||||
type InjectedDependencies = {
|
||||
productCategoryRepository: DAL.TreeRepositoryService
|
||||
}
|
||||
export default class ProductCategoryService<
|
||||
TEntity extends ProductCategory = ProductCategory
|
||||
> {
|
||||
export default class ProductCategoryService {
|
||||
protected readonly productCategoryRepository_: DAL.TreeRepositoryService
|
||||
|
||||
constructor({ productCategoryRepository }: InjectedDependencies) {
|
||||
@@ -30,7 +28,7 @@ export default class ProductCategoryService<
|
||||
productCategoryId: string,
|
||||
config: FindConfig<ProductTypes.ProductCategoryDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
): Promise<ProductCategory> {
|
||||
if (!isDefined(productCategoryId)) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_FOUND,
|
||||
@@ -64,7 +62,7 @@ export default class ProductCategoryService<
|
||||
)
|
||||
}
|
||||
|
||||
return productCategories[0] as TEntity
|
||||
return productCategories[0] as ProductCategory
|
||||
}
|
||||
|
||||
@InjectManager("productCategoryRepository_")
|
||||
@@ -72,7 +70,7 @@ export default class ProductCategoryService<
|
||||
filters: ProductTypes.FilterableProductCategoryProps = {},
|
||||
config: FindConfig<ProductTypes.ProductCategoryDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
): Promise<ProductCategory[]> {
|
||||
const transformOptions = {
|
||||
includeDescendantsTree: filters?.include_descendants_tree || false,
|
||||
includeAncestorsTree: filters?.include_ancestors_tree || false,
|
||||
@@ -101,7 +99,7 @@ export default class ProductCategoryService<
|
||||
queryOptions,
|
||||
transformOptions,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
)) as ProductCategory[]
|
||||
}
|
||||
|
||||
@InjectManager("productCategoryRepository_")
|
||||
@@ -109,7 +107,7 @@ export default class ProductCategoryService<
|
||||
filters: ProductTypes.FilterableProductCategoryProps = {},
|
||||
config: FindConfig<ProductTypes.ProductCategoryDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
): Promise<[ProductCategory[], number]> {
|
||||
const transformOptions = {
|
||||
includeDescendantsTree: filters?.include_descendants_tree || false,
|
||||
includeAncestorsTree: filters?.include_ancestors_tree || false,
|
||||
@@ -138,27 +136,27 @@ export default class ProductCategoryService<
|
||||
queryOptions,
|
||||
transformOptions,
|
||||
sharedContext
|
||||
)) as [TEntity[], number]
|
||||
)) as [ProductCategory[], number]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("productCategoryRepository_")
|
||||
async create(
|
||||
data: ProductTypes.CreateProductCategoryDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
): Promise<ProductCategory[]> {
|
||||
return (await (
|
||||
this.productCategoryRepository_ as unknown as ProductCategoryRepository
|
||||
).create(data, sharedContext)) as TEntity[]
|
||||
).create(data, sharedContext)) as ProductCategory[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("productCategoryRepository_")
|
||||
async update(
|
||||
data: UpdateCategoryInput[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
): Promise<ProductCategory[]> {
|
||||
return (await (
|
||||
this.productCategoryRepository_ as unknown as ProductCategoryRepository
|
||||
).update(data, sharedContext)) as TEntity[]
|
||||
).update(data, sharedContext)) as ProductCategory[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("productCategoryRepository_")
|
||||
|
||||
@@ -55,10 +55,10 @@ import { entityNameToLinkableKeysMap, joinerConfig } from "./../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
productService: ProductService<any>
|
||||
productService: ProductService
|
||||
productVariantService: ModulesSdkTypes.IMedusaInternalService<any, any>
|
||||
productTagService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
productCategoryService: ProductCategoryService<any>
|
||||
productCategoryService: ProductCategoryService
|
||||
productCollectionService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
productImageService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
productTypeService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
@@ -105,9 +105,9 @@ export default class ProductModuleService
|
||||
implements ProductTypes.IProductModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly productService_: ProductService<Product>
|
||||
protected readonly productService_: ProductService
|
||||
protected readonly productVariantService_: ModulesSdkTypes.IMedusaInternalService<ProductVariant>
|
||||
protected readonly productCategoryService_: ProductCategoryService<ProductCategory>
|
||||
protected readonly productCategoryService_: ProductCategoryService
|
||||
protected readonly productTagService_: ModulesSdkTypes.IMedusaInternalService<ProductTag>
|
||||
protected readonly productCollectionService_: ModulesSdkTypes.IMedusaInternalService<ProductCollection>
|
||||
protected readonly productImageService_: ModulesSdkTypes.IMedusaInternalService<ProductImage>
|
||||
|
||||
@@ -18,12 +18,10 @@ type NormalizedFilterableProductProps = ProductTypes.FilterableProductProps & {
|
||||
}
|
||||
}
|
||||
|
||||
export default class ProductService<
|
||||
TEntity extends Product = Product
|
||||
> extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
export default class ProductService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
|
||||
Product
|
||||
)<TEntity> {
|
||||
protected readonly productRepository_: DAL.RepositoryService<TEntity>
|
||||
)<Product> {
|
||||
protected readonly productRepository_: DAL.RepositoryService<Product>
|
||||
|
||||
constructor({ productRepository }: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
@@ -36,9 +34,9 @@ export default class ProductService<
|
||||
@InjectManager("productRepository_")
|
||||
async list(
|
||||
filters: ProductTypes.FilterableProductProps = {},
|
||||
config: FindConfig<TEntity> = {},
|
||||
config: FindConfig<Product> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
): Promise<Product[]> {
|
||||
return await super.list(
|
||||
ProductService.normalizeFilters(filters),
|
||||
config,
|
||||
@@ -51,7 +49,7 @@ export default class ProductService<
|
||||
filters: ProductTypes.FilterableProductProps = {},
|
||||
config: FindConfig<any> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
): Promise<[Product[], number]> {
|
||||
return await super.listAndCount(
|
||||
ProductService.normalizeFilters(filters),
|
||||
config,
|
||||
|
||||
Reference in New Issue
Block a user