Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ShippingPackagingDeleteService | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| delete | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\ShippingPackaging\Services; |
| 4 | |
| 5 | use App\Events\ServiceProcessed; |
| 6 | use App\Models\ShippingPackaging\ShippingPackaging; |
| 7 | use App\Models\User; |
| 8 | use Illuminate\Support\Facades\DB; |
| 9 | use Throwable; |
| 10 | |
| 11 | readonly class ShippingPackagingDeleteService |
| 12 | { |
| 13 | /** |
| 14 | * @param ShippingPackaging $shippingPackaging |
| 15 | * @param User $user |
| 16 | * @return void |
| 17 | * @throws Throwable |
| 18 | */ |
| 19 | public function delete(ShippingPackaging $shippingPackaging, User $user): void |
| 20 | { |
| 21 | try { |
| 22 | DB::beginTransaction(); |
| 23 | |
| 24 | $shippingPackaging->pickingOrders()->update(['shipping_packaging_id' => null]); |
| 25 | $shippingPackaging->delete(); |
| 26 | |
| 27 | DB::commit(); |
| 28 | } catch (Throwable $throwable) { |
| 29 | DB::rollBack(); |
| 30 | throw $throwable; |
| 31 | } |
| 32 | |
| 33 | ServiceProcessed::dispatch(self::class, $user); |
| 34 | } |
| 35 | } |