Merge branch 'dev' into feature/updateDeed

This commit is contained in:
Vincent Alamelle 2023-05-09 14:55:21 +02:00
commit cf7c50f284

View File

@ -47,6 +47,12 @@ export default class DocumentsService extends BaseService {
* @throws {Error} If document cannot be deleted
*/
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);
}
@ -55,12 +61,6 @@ export default class DocumentsService extends BaseService {
* @throws {Error} If document cannot be get by uid
*/
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);
}
}