import { Inject, Injectable } from '@nestjs/common';
import { DatabaseName } from '@domain/value-objects/database-name.vo';
import { CollectionName } from '@domain/value-objects/collection-name.vo';
import {
IMongodbRepository,
MONGODB_REPOSITORY,
} from '@domain/repositories/mongodb.repository.interface';
import { CountDocumentsDto } from './count-documents.dto';
@Injectable()
export class CountDocumentsUseCase {
constructor(
@Inject(MONGODB_REPOSITORY)
private readonly mongoRepository: IMongodbRepository,
) {}
async execute(dto: CountDocumentsDto): Promise<number> {
const dbName = new DatabaseName(dto.database);
const collName = new CollectionName(dto.collection);
return await this.mongoRepository.count(dbName, collName, dto.filter);
}
}