Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| SearchStockOutputResource | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| toArray | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\StockIO\Resources; |
| 4 | |
| 5 | use App\Models\Integration\Integration; |
| 6 | use App\Models\Transferable\Transferable; |
| 7 | use Domain\Shared\Enums\SectorEnum; |
| 8 | use Domain\StockIO\Enums\StockStatusEnum; |
| 9 | use Domain\StockIO\Enums\StockTypeEnum; |
| 10 | use Domain\StockIO\Enums\StockStatusTaskEnum; |
| 11 | use Domain\Team\Resources\TeamResource; |
| 12 | use Illuminate\Database\Eloquent\Collection; |
| 13 | use Illuminate\Http\Request; |
| 14 | use Illuminate\Http\Resources\Json\JsonResource; |
| 15 | |
| 16 | /** |
| 17 | * @property ?StockStatusEnum $status |
| 18 | * @property ?string $observation |
| 19 | * @property Collection $items |
| 20 | * @property StockTypeEnum $type |
| 21 | * @property array $data |
| 22 | * @property Transferable|null $transferable |
| 23 | * @property int $id |
| 24 | * @property boolean $urgent |
| 25 | * @property string $created_at |
| 26 | * @property Integration $integration |
| 27 | * @property int $reason |
| 28 | * @property SectorEnum $sector |
| 29 | */ |
| 30 | class SearchStockOutputResource extends JsonResource |
| 31 | { |
| 32 | public function toArray(Request $request): array |
| 33 | { |
| 34 | return [ |
| 35 | 'id' => $this->id, |
| 36 | 'urgent' => $this->urgent, |
| 37 | 'observation' => $this->observation, |
| 38 | 'status' => $this->status?->value, |
| 39 | 'type' => $this->type->value, |
| 40 | 'reason' => $this->reason, |
| 41 | 'sector' => $this->sector->value, |
| 42 | 'team'=> TeamResource::make($this->whenLoaded('team')), |
| 43 | 'items_count' => $this->whenCounted('stockIOProducts'), |
| 44 | 'picking_orders_count' => $this->whenCounted('pickingOrders'), |
| 45 | 'transferable_id' => $this->whenLoaded('transferable', $this->transferable?->getKey()), |
| 46 | 'data' => $this->whenLoaded('integration', fn() => $this->integration->getAttribute('parameters')), |
| 47 | 'created_at' => (string)$this->created_at, |
| 48 | 'all_items_in_task' => StockStatusTaskEnum::from($this->picking_status), |
| 49 | ]; |
| 50 | } |
| 51 | |
| 52 | } |