26 lines
980 B
TypeScript
26 lines
980 B
TypeScript
import { ApplicationError } from "../../../../../shared/domain/errors/application-error";
|
|
import { DocumentRepository } from "../../../domain/repositories/document.repository";
|
|
import { DocumentStoragePort } from "../../ports/document-storage.port";
|
|
import { DeleteDocumentCommand } from "./delete-document.command";
|
|
|
|
export class DeleteDocumentHandler {
|
|
constructor(
|
|
private readonly documentRepository: DocumentRepository,
|
|
private readonly documentStorage: DocumentStoragePort
|
|
) {}
|
|
|
|
public async execute(command: DeleteDocumentCommand): Promise<void> {
|
|
const document = await this.documentRepository.findByIdForTenant(
|
|
command.tenantId,
|
|
command.documentId
|
|
);
|
|
|
|
if (!document) {
|
|
throw new ApplicationError("Document not found", 404, "DOCUMENT_NOT_FOUND");
|
|
}
|
|
|
|
await this.documentStorage.delete(command.tenantId, document.storageKey);
|
|
await this.documentRepository.deleteForTenant(command.tenantId, command.documentId);
|
|
}
|
|
}
|