feat: add void and delete endpoints for qr batches, fix batch list status counts
This commit is contained in:
@@ -10,11 +10,18 @@ class QrCodeBatchResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$statusCounts = $this->whenLoaded('codes', function () {
|
||||
return $this->codes->groupBy(fn (QrCode $c) => (string) $c->status)
|
||||
$statusCounts = [
|
||||
'active' => $this->active_codes_count ?? 0,
|
||||
'used' => $this->used_codes_count ?? 0,
|
||||
'voided' => $this->voided_codes_count ?? 0,
|
||||
];
|
||||
|
||||
// If the relation is loaded (like on the show endpoint), compute it accurately just in case
|
||||
if ($this->relationLoaded('codes') && ! isset($this->active_codes_count)) {
|
||||
$statusCounts = $this->codes->groupBy(fn (QrCode $c) => (string) $c->status)
|
||||
->map(fn ($group) => $group->count())
|
||||
->all();
|
||||
});
|
||||
}
|
||||
|
||||
return [
|
||||
'batch_number' => $this->batch_number,
|
||||
|
||||
Reference in New Issue
Block a user