Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ShippingPackagingStoreService | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| store | |
0.00% |
0 / 11 |
|
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 Domain\ShippingPackaging\DTOs\ShippingPackagingDTO; |
| 9 | use Domain\ShippingPackaging\Enums\ShippingPackagingStatusEnum; |
| 10 | use Domain\Team\Exceptions\UserDoesNotBelongToTeamException; |
| 11 | |
| 12 | readonly class ShippingPackagingStoreService |
| 13 | { |
| 14 | public function store(ShippingPackagingDTO $shippingPackagingDTO, User $user): ShippingPackaging |
| 15 | { |
| 16 | if ($user->teams()->where('team_id', $shippingPackagingDTO->team->getKey())->doesntExist()) { |
| 17 | throw new UserDoesNotBelongToTeamException(__('Team does not belong to this user')); |
| 18 | } |
| 19 | |
| 20 | $shippingPackaging = new ShippingPackaging(); |
| 21 | $shippingPackaging->team()->associate($shippingPackagingDTO->team); |
| 22 | $shippingPackaging->fill($shippingPackagingDTO->toArray()); |
| 23 | $shippingPackaging->packaging()->associate($shippingPackagingDTO->packaging); |
| 24 | $shippingPackaging->responsible()->associate($user); |
| 25 | $shippingPackaging->setAttribute('status', ShippingPackagingStatusEnum::STARTED); |
| 26 | $shippingPackaging->save(); |
| 27 | |
| 28 | ServiceProcessed::dispatch(self::class, $user); |
| 29 | return $shippingPackaging; |
| 30 | } |
| 31 | } |