feat(ticket): validate ticket capability status and use transaction in cancel and refund
This commit is contained in:
parent
2ddb046c26
commit
6384c0046d
|
|
@ -80,14 +80,23 @@ class AdminAppTicketService
|
||||||
|
|
||||||
public function cancel(Tenant $tenant, int $ticketId): Ticket
|
public function cancel(Tenant $tenant, int $ticketId): Ticket
|
||||||
{
|
{
|
||||||
$ticket = Ticket::query()
|
return DB::transaction(function () use ($tenant, $ticketId): Ticket {
|
||||||
->where('tenant_code', $tenant->codigo)
|
$ticket = Ticket::query()
|
||||||
->findOrFail($ticketId);
|
->where('tenant_code', $tenant->codigo)
|
||||||
|
->lockForUpdate()
|
||||||
|
->findOrFail($ticketId);
|
||||||
|
|
||||||
$ticket->markAsCancelled();
|
if (! $ticket->can_cancel()) {
|
||||||
$ticket->save();
|
throw ValidationException::withMessages([
|
||||||
|
'status' => 'El ticket debe estar activo para poder cancelarlo.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
return $ticket->refresh()->load(self::RELATIONS);
|
$ticket->markAsCancelled();
|
||||||
|
$ticket->save();
|
||||||
|
|
||||||
|
return $ticket->refresh()->load(self::RELATIONS);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function refund(Tenant $tenant, int $ticketId, string $refundType): Ticket
|
public function refund(Tenant $tenant, int $ticketId, string $refundType): Ticket
|
||||||
|
|
@ -100,6 +109,18 @@ class AdminAppTicketService
|
||||||
->lockForUpdate()
|
->lockForUpdate()
|
||||||
->findOrFail($ticketId);
|
->findOrFail($ticketId);
|
||||||
|
|
||||||
|
if (! $ticket->can_refund()) {
|
||||||
|
if ($ticket->status !== Ticket::STATUS_ACTIVE) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'status' => 'El ticket debe estar activo para poder reembolsarlo.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'refund' => 'El reembolso no está disponible para este ticket.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$purchaseItem = PurchaseItem::query()
|
$purchaseItem = PurchaseItem::query()
|
||||||
->lockForUpdate()
|
->lockForUpdate()
|
||||||
->find($ticket->source_purchase_item_id);
|
->find($ticket->source_purchase_item_id);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue