feat: add void and delete endpoints for qr batches, fix batch list status counts

This commit is contained in:
Developer
2026-06-30 15:03:25 +08:00
parent 7452848cf9
commit cfb09fd5fb
3 changed files with 44 additions and 4 deletions

View File

@@ -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,