🐛 Cant delete a document with archived file in it (#203)

This commit is contained in:
Maxime Sallerin 2024-08-21 11:32:36 +02:00 committed by GitHub
parent 6aaf8749d6
commit 8b636dadd3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -62,7 +62,9 @@ export default class DocumentsService extends BaseService {
if (!documentEntity) throw new Error("document not found"); if (!documentEntity) throw new Error("document not found");
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" }); const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
if (document.files && document.files.length !== 0) { const isDocumentEmpty = document.files && !document!.files.find((file) => file.archived_at === null);
if (!isDocumentEmpty) {
throw new Error("Can't delete a document with file"); throw new Error("Can't delete a document with file");
} }
return this.documentsRepository.delete(uid); return this.documentsRepository.delete(uid);

View File

@ -62,7 +62,9 @@ export default class DocumentsService extends BaseService {
if (!documentEntity) throw new Error("document not found"); if (!documentEntity) throw new Error("document not found");
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" }); const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
if (document.files && document.files.length !== 0 && document.document_status !== "REFUSED") { const isDocumentEmpty = document.files && !document!.files.find((file) => file.archived_at === null);
if (!isDocumentEmpty && document.document_status !== "REFUSED") {
throw new Error("Can't delete a document with file"); throw new Error("Can't delete a document with file");
} }
return this.documentsRepository.delete(uid); return this.documentsRepository.delete(uid);