From d912042f882ac73caadbd34c66d283f40761de09 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Fri, 6 Dec 2024 17:43:56 +0100 Subject: [PATCH] fix: use overloading to marke deprecated methods signatures --- api/src/utils/generics/base-repository.ts | 36 ++++++++++++++++--- api/src/utils/generics/base-service.ts | 44 +++++++++++++++++++++-- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/api/src/utils/generics/base-repository.ts b/api/src/utils/generics/base-repository.ts index 8aed82e5..717c3f78 100644 --- a/api/src/utils/generics/base-repository.ts +++ b/api/src/utils/generics/base-repository.ts @@ -275,12 +275,26 @@ export abstract class BaseRepository< } } + /** + * @deprecated + */ + async find( + filter: TFilterQuery, + pageQuery?: QuerySortDto, + projection?: ProjectionType, + ): Promise; + async find( filter: TFilterQuery, - // TODO: QuerySortDto type need to be removed pageQuery?: QuerySortDto | PageQueryDto, projection?: ProjectionType, - ) { + ): Promise; + + async find( + filter: TFilterQuery, + pageQuery?: QuerySortDto | PageQueryDto, + projection?: ProjectionType, + ): Promise { const query = this.findQuery(filter, pageQuery, projection); return await this.execute(query, this.cls); } @@ -291,12 +305,26 @@ export abstract class BaseRepository< } } + /** + * @deprecated + */ + async findAndPopulate( + filters: TFilterQuery, + pageQuery?: QuerySortDto, + projection?: ProjectionType, + ): Promise; + + async findAndPopulate( + filters: TFilterQuery, + pageQuery?: PageQueryDto, + projection?: ProjectionType, + ): Promise; + async findAndPopulate( filters: TFilterQuery, - // TODO: QuerySortDto need to be removed pageQuery?: QuerySortDto | PageQueryDto, projection?: ProjectionType, - ) { + ): Promise { this.ensureCanPopulate(); const query = this.findQuery(filters, pageQuery, projection).populate( this.populate, diff --git a/api/src/utils/generics/base-service.ts b/api/src/utils/generics/base-service.ts index 4a27e857..9686eb76 100644 --- a/api/src/utils/generics/base-service.ts +++ b/api/src/utils/generics/base-service.ts @@ -44,21 +44,59 @@ export abstract class BaseService< return await this.repository.findOneAndPopulate(criteria, projection); } + /** + * @deprecated + */ + async find( + filter: TFilterQuery, + pageQuery?: QuerySortDto, + projection?: ProjectionType, + ): Promise; + + async find( + filter: TFilterQuery, + pageQuery?: PageQueryDto, + projection?: ProjectionType, + ): Promise; + async find( filter: TFilterQuery, - // TODO: QuerySortDto type need to be removed pageQuery?: QuerySortDto | PageQueryDto, projection?: ProjectionType, ): Promise { + if (Array.isArray(pageQuery)) + return await this.repository.find(filter, pageQuery, projection); + return await this.repository.find(filter, pageQuery, projection); } + /** + * @deprecated + */ + async findAndPopulate( + filters: TFilterQuery, + pageQuery?: QuerySortDto, + projection?: ProjectionType, + ): Promise; + + async findAndPopulate( + filters: TFilterQuery, + pageQuery?: PageQueryDto, + projection?: ProjectionType, + ): Promise; + async findAndPopulate( filters: TFilterQuery, - // TODO: QuerySortDto type need to be removed pageQuery?: QuerySortDto | PageQueryDto, projection?: ProjectionType, - ) { + ): Promise { + if (Array.isArray(pageQuery)) + return await this.repository.findAndPopulate( + filters, + pageQuery, + projection, + ); + return await this.repository.findAndPopulate( filters, pageQuery,