fix(product): Serialize typings (#4602)

What:
Fix the serializer
This commit is contained in:
Adrien de Peretti authored and GitHub committed 2023-07-26 08:08:36 +00:00
1 parent 173684371b
commit 585ebf2454
4 files changed
+22 -40

No files matched your search

+9 -19
View File
@@ -74,16 +74,13 @@ const updateDeletedAtRecursively = async <T extends object = any>(
}
}
const serializer = <
T extends object | object[],
TResult extends object | object[]
>(
data: T,
const serializer = <TOutput extends object>(
data: any,
options?: any
): Promise<TResult> => {
): Promise<TOutput> => {
options ??= {}
const result = serialize(data, options)
return Array.isArray(data) ? result : result[0]
return result as unknown as Promise<TOutput>
}
export abstract class AbstractBaseRepository<T = any>
@@ -110,11 +107,11 @@ export abstract class AbstractBaseRepository<T = any>
return await transactionWrapper.apply(this, arguments)
}
serialize<
TData extends object | object[] = object[],
TResult extends object | object[] = object[]
>(data: TData, options?: any): Promise<TResult> {
return serializer<TData, TResult>(data, options)
async serialize<TOutput extends object | object[]>(
data: any,
options?: any
): Promise<TOutput> {
return await serializer<TOutput>(data, options)
}
abstract find(options?: DAL.FindOptions<T>, context?: Context)
@@ -203,13 +200,6 @@ export class BaseRepository extends AbstractBaseRepository {
super(...arguments)
}
serialize<
TData extends object | object[] = object[],
TResult extends object | object[] = object[]
>(data: TData, options?: any): Promise<TResult> {
return serializer<TData, TResult>(data, options)
}
create(data: unknown[], context?: Context): Promise<any[]> {
throw new Error("Method not implemented.")
}
@@ -285,10 +285,7 @@ export default class ProductModuleService<
async create(data: ProductTypes.CreateProductDTO[], sharedContext?: Context) {
const products = await this.create_(data, sharedContext)
return this.baseRepository_.serialize<
TProduct[],
ProductTypes.ProductDTO[]
>(products, {
return this.baseRepository_.serialize<ProductTypes.ProductDTO[]>(products, {
populate: true,
})
}
@@ -425,10 +422,7 @@ export default class ProductModuleService<
): Promise<ProductTypes.ProductDTO[]> {
const products = await this.softDelete_(productIds, sharedContext)
return this.baseRepository_.serialize<
TProduct[],
ProductTypes.ProductDTO[]
>(products, {
return this.baseRepository_.serialize<ProductTypes.ProductDTO[]>(products, {
populate: true,
})
}
@@ -447,10 +441,7 @@ export default class ProductModuleService<
): Promise<ProductTypes.ProductDTO[]> {
const products = await this.restore_(productIds, sharedContext)
return this.baseRepository_.serialize<
TProduct[],
ProductTypes.ProductDTO[]
>(products, {
return this.baseRepository_.serialize<ProductTypes.ProductDTO[]>(products, {
populate: true,
})
}