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 { UpdateDocumentsDto } from './update-documents.dto';
@Injectable()
export class UpdateDocumentsUseCase {
constructor(
@Inject(MONGODB_REPOSITORY)
private readonly mongoRepository: IMongodbRepository,
) {}
async execute(dto: UpdateDocumentsDto): Promise<number> {
const dbName = new DatabaseName(dto.database);
const collName = new CollectionName(dto.collection);
return await this.mongoRepository.updateMany(dbName, collName, dto.filter, dto.update);
}
}