Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| PickedItemChangeObservationService | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| changeObservation | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\PickingOrder\Services; |
| 4 | |
| 5 | use App\Events\ServiceProcessed; |
| 6 | use App\Models\PickedItem; |
| 7 | use App\Models\User; |
| 8 | use Domain\PickingOrder\DTOs\PickedItemObservationDTO; |
| 9 | use Exception; |
| 10 | use Illuminate\Support\Facades\DB; |
| 11 | |
| 12 | readonly class PickedItemChangeObservationService |
| 13 | { |
| 14 | |
| 15 | /** |
| 16 | * @param PickedItem $pickedItem |
| 17 | * @param User $user |
| 18 | * @return PickedItem |
| 19 | * @throws Exception |
| 20 | */ |
| 21 | public function changeObservation(PickedItemObservationDTO $pickedItemObservationDTO, PickedItem $pickedItem, User $user): PickedItem |
| 22 | { |
| 23 | try { |
| 24 | DB::beginTransaction(); |
| 25 | $pickedItem->setAttribute('observation', $pickedItemObservationDTO->observation); |
| 26 | $pickedItem->save(); |
| 27 | |
| 28 | DB::commit(); |
| 29 | } catch (Exception $exception) { |
| 30 | DB::rollBack(); |
| 31 | throw $exception; |
| 32 | } |
| 33 | |
| 34 | ServiceProcessed::dispatch(self::class, $user); |
| 35 | return $pickedItem; |
| 36 | } |
| 37 | } |