Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
InvoiceItemUpdateService
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 update
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace Domain\Invoice\Services;
4
5use App\Events\ServiceProcessed;
6use App\Models\Integration\Integration;
7use App\Models\Invoice\InvoiceItem;
8use App\Models\User;
9use Domain\Integration\Services\IntegrationUpdateService;
10use Domain\Invoice\DTOs\UpdateInvoiceItemDTO;
11use Illuminate\Support\Facades\DB;
12use Throwable;
13
14readonly 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}