Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| OrderProductsResource | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| toArray | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\PickingOrder\Resources; |
| 4 | |
| 5 | use Domain\Integration\Resources\IntegrationResource; |
| 6 | use Domain\Item\Resource\ItemResource; |
| 7 | use Domain\Product\Resources\ProductResource; |
| 8 | use Domain\StockIO\Resources\StockOIResource; |
| 9 | use Domain\StockIO\Services\StockIOProductMissingAmountService; |
| 10 | use Illuminate\Http\Request; |
| 11 | use Illuminate\Http\Resources\Json\JsonResource; |
| 12 | |
| 13 | /** |
| 14 | * @property int $amount |
| 15 | * @property int $id |
| 16 | */ |
| 17 | class OrderProductsResource extends JsonResource |
| 18 | { |
| 19 | public function toArray(Request $request): array |
| 20 | { |
| 21 | $missingAmount = (new StockIOProductMissingAmountService())->resolve($this->resource); |
| 22 | |
| 23 | return [ |
| 24 | 'id' => $this->id, |
| 25 | 'amount' => $this->amount, |
| 26 | 'quantity_missing' => $missingAmount, |
| 27 | 'type' => $this->pivot ? $this->pivot->type : null, |
| 28 | 'status' => $this->status->value, |
| 29 | 'picked' => $this->whenAppended('picked'), |
| 30 | 'items' => ItemResource::collection($this->whenLoaded('items')), |
| 31 | 'picked_items' => PickedItemResource::collection($this->whenLoaded('pickedItems')), |
| 32 | 'product' => ProductResource::make($this->whenLoaded('product')), |
| 33 | 'integration' => IntegrationResource::make($this->whenLoaded('integration')), |
| 34 | 'stock_io' => StockOIResource::make($this->whenLoaded('stockIO')), |
| 35 | ]; |
| 36 | } |
| 37 | } |