Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
ShippingPackagingPickingOrderResource
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 toArray
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Domain\ShippingPackaging\Resources;
4
5use App\Models\ShippingPackaging\ShippingPackaging;
6use App\Models\ShippingPackaging\ShippingPackagingProduct;
7use Domain\Packaging\Resources\PackagingResource;
8use Domain\ShippingPackaging\Enums\ShippingPackagingStatusEnum;
9use Domain\ShippingPackaging\Enums\ShippingPackagingTypeEnum;
10use Domain\User\Resources\UserSensitiveResource;
11use Illuminate\Database\Eloquent\Collection;
12use Illuminate\Http\Request;
13use Illuminate\Http\Resources\Json\JsonResource;
14
15/**
16 * @property ShippingPackagingStatusEnum $status
17 * @property int $id
18 * @property string $created_at
19 * @property string $updated_at
20 * @property int $volume
21 * @property ShippingPackagingTypeEnum $type
22 * @property Collection $pickingOrders
23 */
24class ShippingPackagingPickingOrderResource extends JsonResource
25{
26
27    public function toArray(Request $request): array
28    {
29        /** @var ShippingPackaging $shippingPackaging */
30        $shippingPackaging = $this->resource;
31
32        $stockIO = $shippingPackaging->products->map(function (ShippingPackagingProduct $shippingPackagingProduct) {
33            return $shippingPackagingProduct->pickedItem->stockIOProduct->stockIO;
34        })->unique();
35
36        return [
37            'id' => $this->id,
38            'status' => $this->status->value,
39            'volume' => $this->volume,
40            'type' => $this->type->value,
41            'observation' => $this->observation,
42            'packaging' => PackagingResource::make($this->whenLoaded('packaging')),
43            'responsible' => UserSensitiveResource::make($this->whenLoaded('responsible')),
44            'created_at' => $this->created_at,
45            'updated_at' => $this->updated_at,
46        ];
47    }
48}