mirror of
https://github.com/hexastack/hexabot
synced 2025-01-22 10:35:37 +00:00
fix: add retro compatibility for find and findAndPopulate methods
This commit is contained in:
parent
62e59069dd
commit
d3b5070407
@ -55,7 +55,7 @@ import { SubscriberService } from '../services/subscriber.service';
|
||||
@UseInterceptors(CsrfInterceptor)
|
||||
@Controller('message')
|
||||
export class MessageController extends BaseController<
|
||||
Message,
|
||||
AnyMessage,
|
||||
MessageStub,
|
||||
MessagePopulate,
|
||||
MessageFull
|
||||
|
@ -257,20 +257,28 @@ export abstract class BaseRepository<
|
||||
|
||||
protected findQuery(
|
||||
filter: TFilterQuery<T>,
|
||||
pageQuery?: PageQueryDto<T>,
|
||||
// TODO: QuerySortDto<T> type need to be removed
|
||||
pageQuery?: QuerySortDto<T> | PageQueryDto<T>,
|
||||
projection?: ProjectionType<T>,
|
||||
) {
|
||||
const { skip = 0, limit, sort = ['createdAt', 'asc'] } = pageQuery || {};
|
||||
const query = this.model.find<T>(filter, projection);
|
||||
return query
|
||||
.skip(skip)
|
||||
.limit(limit)
|
||||
.sort([sort] as [string, SortOrder][]);
|
||||
// TODO: current block need to be removed
|
||||
if (Array.isArray(pageQuery)) {
|
||||
const query = this.model.find<T>(filter, projection);
|
||||
return query.sort([pageQuery] as [string, SortOrder][]);
|
||||
} else {
|
||||
const { skip = 0, limit, sort = ['createdAt', 'asc'] } = pageQuery || {};
|
||||
const query = this.model.find<T>(filter, projection);
|
||||
return query
|
||||
.skip(skip)
|
||||
.limit(limit)
|
||||
.sort([sort] as [string, SortOrder][]);
|
||||
}
|
||||
}
|
||||
|
||||
async find(
|
||||
filter: TFilterQuery<T>,
|
||||
pageQuery?: PageQueryDto<T>,
|
||||
// TODO: QuerySortDto<T> type need to be removed
|
||||
pageQuery?: QuerySortDto<T> | PageQueryDto<T>,
|
||||
projection?: ProjectionType<T>,
|
||||
) {
|
||||
const query = this.findQuery(filter, pageQuery, projection);
|
||||
@ -285,7 +293,8 @@ export abstract class BaseRepository<
|
||||
|
||||
async findAndPopulate(
|
||||
filters: TFilterQuery<T>,
|
||||
pageQuery?: PageQueryDto<T>,
|
||||
// TODO: QuerySortDto<T> need to be removed
|
||||
pageQuery?: QuerySortDto<T> | PageQueryDto<T>,
|
||||
projection?: ProjectionType<T>,
|
||||
) {
|
||||
this.ensureCanPopulate();
|
||||
|
@ -46,7 +46,8 @@ export abstract class BaseService<
|
||||
|
||||
async find(
|
||||
filter: TFilterQuery<T>,
|
||||
pageQuery?: PageQueryDto<T>,
|
||||
// TODO: QuerySortDto<T> type need to be removed
|
||||
pageQuery?: QuerySortDto<T> | PageQueryDto<T>,
|
||||
projection?: ProjectionType<T>,
|
||||
): Promise<T[]> {
|
||||
return await this.repository.find(filter, pageQuery, projection);
|
||||
@ -54,7 +55,8 @@ export abstract class BaseService<
|
||||
|
||||
async findAndPopulate(
|
||||
filters: TFilterQuery<T>,
|
||||
pageQuery?: PageQueryDto<T>,
|
||||
// TODO: QuerySortDto<T> type need to be removed
|
||||
pageQuery?: QuerySortDto<T> | PageQueryDto<T>,
|
||||
projection?: ProjectionType<T>,
|
||||
) {
|
||||
return await this.repository.findAndPopulate(
|
||||
|
Loading…
Reference in New Issue
Block a user