fix: use overloading to marke deprecated methods signatures

This commit is contained in:
yassinedorbozgithub 2024-12-06 17:43:56 +01:00
parent d3b5070407
commit d912042f88
2 changed files with 73 additions and 7 deletions

View File

@ -275,12 +275,26 @@ export abstract class BaseRepository<
}
}
/**
* @deprecated
*/
async find(
filter: TFilterQuery<T>,
pageQuery?: QuerySortDto<T>,
projection?: ProjectionType<T>,
): Promise<T[]>;
async find(
filter: TFilterQuery<T>,
// TODO: QuerySortDto<T> type need to be removed
pageQuery?: QuerySortDto<T> | PageQueryDto<T>,
projection?: ProjectionType<T>,
) {
): Promise<T[]>;
async find(
filter: TFilterQuery<T>,
pageQuery?: QuerySortDto<T> | PageQueryDto<T>,
projection?: ProjectionType<T>,
): Promise<T[]> {
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<T>,
pageQuery?: QuerySortDto<T>,
projection?: ProjectionType<T>,
): Promise<TFull[]>;
async findAndPopulate(
filters: TFilterQuery<T>,
pageQuery?: PageQueryDto<T>,
projection?: ProjectionType<T>,
): Promise<TFull[]>;
async findAndPopulate(
filters: TFilterQuery<T>,
// TODO: QuerySortDto<T> need to be removed
pageQuery?: QuerySortDto<T> | PageQueryDto<T>,
projection?: ProjectionType<T>,
) {
): Promise<TFull[]> {
this.ensureCanPopulate();
const query = this.findQuery(filters, pageQuery, projection).populate(
this.populate,

View File

@ -44,21 +44,59 @@ export abstract class BaseService<
return await this.repository.findOneAndPopulate(criteria, projection);
}
/**
* @deprecated
*/
async find(
filter: TFilterQuery<T>,
pageQuery?: QuerySortDto<T>,
projection?: ProjectionType<T>,
): Promise<T[]>;
async find(
filter: TFilterQuery<T>,
pageQuery?: PageQueryDto<T>,
projection?: ProjectionType<T>,
): Promise<T[]>;
async find(
filter: TFilterQuery<T>,
// TODO: QuerySortDto<T> type need to be removed
pageQuery?: QuerySortDto<T> | PageQueryDto<T>,
projection?: ProjectionType<T>,
): Promise<T[]> {
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<T>,
pageQuery?: QuerySortDto<T>,
projection?: ProjectionType<T>,
): Promise<TFull[]>;
async findAndPopulate(
filters: TFilterQuery<T>,
pageQuery?: PageQueryDto<T>,
projection?: ProjectionType<T>,
): Promise<TFull[]>;
async findAndPopulate(
filters: TFilterQuery<T>,
// TODO: QuerySortDto<T> type need to be removed
pageQuery?: QuerySortDto<T> | PageQueryDto<T>,
projection?: ProjectionType<T>,
) {
): Promise<TFull[]> {
if (Array.isArray(pageQuery))
return await this.repository.findAndPopulate(
filters,
pageQuery,
projection,
);
return await this.repository.findAndPopulate(
filters,
pageQuery,