Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| InvoiceItemUpdateService | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| update | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\Invoice\Services; |
| 4 | |
| 5 | use App\Events\ServiceProcessed; |
| 6 | use App\Models\Integration\Integration; |
| 7 | use App\Models\Invoice\InvoiceItem; |
| 8 | use App\Models\User; |
| 9 | use Domain\Integration\Services\IntegrationUpdateService; |
| 10 | use Domain\Invoice\DTOs\UpdateInvoiceItemDTO; |
| 11 | use Illuminate\Support\Facades\DB; |
| 12 | use Throwable; |
| 13 | |
| 14 | readonly class InvoiceItemUpdateService |
| 15 | { |
| 16 | public function update(UpdateInvoiceItemDTO $updateInvoiceItemDTO, InvoiceItem $invoiceItem, User $user): InvoiceItem |
| 17 | { |
| 18 | try { |
| 19 | DB::beginTransaction(); |
| 20 | |
| 21 | $invoiceItem->fill($updateInvoiceItemDTO->toArray()); |
| 22 | $invoiceItem->save(); |
| 23 | |
| 24 | $integration = Integration::query() |
| 25 | ->where('integrable_type', InvoiceItem::class) |
| 26 | ->where('integrable_id', $invoiceItem->getKey()) |
| 27 | ->first(); |
| 28 | |
| 29 | (new IntegrationUpdateService())->update($updateInvoiceItemDTO->integration, $integration, $user); |
| 30 | |
| 31 | DB::commit(); |
| 32 | } catch (Throwable $exception) { |
| 33 | DB::rollBack(); |
| 34 | throw $exception; |
| 35 | } |
| 36 | |
| 37 | ServiceProcessed::dispatch(self::class, $user); |
| 38 | return $invoiceItem; |
| 39 | } |
| 40 | } |