feat: deleteIfNoRelations

This commit is contained in:
Ahmed Bouhuolia
2025-06-28 22:35:29 +02:00
parent 0ca98c7ae4
commit fa5c3bd955
11 changed files with 229 additions and 143 deletions

View File

@@ -39,9 +39,6 @@ export class DeleteBranchService {
.query()
.findById(branchId)
.throwIfNotFound();
// .queryAndThrowIfHasRelations({
// type: ERRORS.BRANCH_HAS_ASSOCIATED_TRANSACTIONS,
// });
// Authorize the branch before deleting.
await this.authorize(branchId);
@@ -54,8 +51,10 @@ export class DeleteBranchService {
trx,
} as IBranchDeletePayload);
await this.branchModel().query().findById(branchId).delete();
await this.branchModel().query().findById(branchId).deleteIfNoRelations({
type: ERRORS.BRANCH_HAS_ASSOCIATED_TRANSACTIONS,
message: 'Branch has associated transactions',
});
// Triggers `onBranchCreate` event.
await this.eventPublisher.emitAsync(events.warehouse.onEdited, {
oldBranch,