hotfix delete document

This commit is contained in:
Vincent Alamelle 2023-05-09 14:54:56 +02:00
parent 9a26118839
commit 385d886fb4

View File

@ -47,6 +47,12 @@ export default class DocumentsService extends BaseService {
* @throws {Error} If document cannot be deleted * @throws {Error} If document cannot be deleted
*/ */
public async delete(uid: string): Promise<Documents> { public async delete(uid: string): Promise<Documents> {
const documentEntity = await this.documentsRepository.findOneByUid(uid, { office_folder_has_customers: true });
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
if (document.files && document.files.length !== 0) {
throw new Error("Can't delete a document with file");
}
return this.documentsRepository.delete(uid); return this.documentsRepository.delete(uid);
} }
@ -55,12 +61,6 @@ export default class DocumentsService extends BaseService {
* @throws {Error} If document cannot be get by uid * @throws {Error} If document cannot be get by uid
*/ */
public async getByUid(uid: string, query?: any) { public async getByUid(uid: string, query?: any) {
const documentEntity = await this.documentsRepository.findOneByUid(uid, { office_folder_has_customers: true });
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
if (document.files && document.files.length !== 0) {
throw new Error("Can't delete a document with file");
}
return this.documentsRepository.findOneByUid(uid, query); return this.documentsRepository.findOneByUid(uid, query);
} }
} }