Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| CustomerStoreService | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| store | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Customer\Services; |
| 4 | |
| 5 | use App\Events\ServiceProcessed; |
| 6 | use App\Models\Customer\Customer; |
| 7 | use App\Models\Team\Team; |
| 8 | use App\Models\User; |
| 9 | use Domain\Customer\DTOs\CustomerDTO; |
| 10 | use Domain\Integration\Services\IntegrationStoreService; |
| 11 | use Exception; |
| 12 | use Illuminate\Support\Facades\DB; |
| 13 | |
| 14 | readonly class CustomerStoreService |
| 15 | { |
| 16 | |
| 17 | /** |
| 18 | * @param CustomerDTO $customerDTO |
| 19 | * @param User $user |
| 20 | * @return Customer |
| 21 | * @throws Exception |
| 22 | */ |
| 23 | public function store(CustomerDTO $customerDTO, User $user): Customer |
| 24 | { |
| 25 | |
| 26 | try { |
| 27 | DB::beginTransaction(); |
| 28 | |
| 29 | $customer = new Customer(); |
| 30 | $customer->fill($customerDTO->toArray()); |
| 31 | $customer->team()->associate($customerDTO->team); |
| 32 | $customer->save(); |
| 33 | |
| 34 | (new IntegrationStoreService())->store($customerDTO->integrationCustomerDTO, $customer, $user); |
| 35 | |
| 36 | DB::commit(); |
| 37 | } catch (Exception $exception) { |
| 38 | DB::rollBack(); |
| 39 | throw $exception; |
| 40 | } |
| 41 | |
| 42 | ServiceProcessed::dispatch(self::class, $user); |
| 43 | return $customer; |
| 44 | } |
| 45 | |
| 46 | } |