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

@@ -49,9 +49,6 @@ export class DeleteWarehouseService {
.query()
.findById(warehouseId)
.throwIfNotFound();
// .queryAndThrowIfHasRelations({
// type: ERRORS.WAREHOUSE_HAS_ASSOCIATED_TRANSACTIONS,
// });
// Validates the given warehouse before deleting.
await this.authorize(warehouseId);
@@ -70,8 +67,13 @@ export class DeleteWarehouseService {
eventPayload,
);
// Deletes the given warehouse from the storage.
await this.warehouseModel().query().findById(warehouseId).delete();
await this.warehouseModel()
.query()
.findById(warehouseId)
.deleteIfNoRelations({
type: ERRORS.WAREHOUSE_HAS_ASSOCIATED_TRANSACTIONS,
message: 'Warehouse has associated transactions',
});
// Triggers `onWarehouseCreated`.
await this.eventPublisher.emitAsync(
events.warehouse.onDeleted,