Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| SupplierStoreService | |
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\Supplier\Services; |
| 4 | |
| 5 | use App\Events\ServiceProcessed; |
| 6 | use App\Models\Supplier; |
| 7 | use App\Models\User; |
| 8 | use Domain\Integration\Services\IntegrationStoreService; |
| 9 | use Domain\Supplier\DTOs\StoreSupplierDTO; |
| 10 | use Illuminate\Support\Facades\DB; |
| 11 | use Throwable; |
| 12 | |
| 13 | readonly class SupplierStoreService |
| 14 | { |
| 15 | public function store(StoreSupplierDTO $storeSupplierDTO, User $user): Supplier |
| 16 | { |
| 17 | try { |
| 18 | DB::beginTransaction(); |
| 19 | |
| 20 | $supplier = new Supplier(); |
| 21 | $supplier->fill($storeSupplierDTO->toArray()); |
| 22 | $supplier->save(); |
| 23 | |
| 24 | (new IntegrationStoreService())->store($storeSupplierDTO->integration, $supplier, $user); |
| 25 | |
| 26 | DB::commit(); |
| 27 | } catch (Throwable $exception) { |
| 28 | DB::rollBack(); |
| 29 | throw $exception; |
| 30 | } |
| 31 | |
| 32 | ServiceProcessed::dispatch(self::class, $user); |
| 33 | return $supplier; |
| 34 | } |
| 35 | } |