diff --git a/backend/app/Http/Request/Attendee/CreateAttendeeRequest.php b/backend/app/Http/Request/Attendee/CreateAttendeeRequest.php index d5a6faee..880c1881 100644 --- a/backend/app/Http/Request/Attendee/CreateAttendeeRequest.php +++ b/backend/app/Http/Request/Attendee/CreateAttendeeRequest.php @@ -13,7 +13,7 @@ public function rules(): array { return [ 'ticket_id' => ['int', 'required'], - 'ticket_price_id' => ['int', 'nullable'], + 'ticket_price_id' => ['int', 'nullable', 'required'], 'email' => ['required', 'email'], 'first_name' => 'string|required', 'last_name' => 'string', diff --git a/backend/app/Services/Handlers/Attendee/CreateAttendeeHandler.php b/backend/app/Services/Handlers/Attendee/CreateAttendeeHandler.php index 8202210a..484a4869 100644 --- a/backend/app/Services/Handlers/Attendee/CreateAttendeeHandler.php +++ b/backend/app/Services/Handlers/Attendee/CreateAttendeeHandler.php @@ -69,9 +69,11 @@ public function handle(CreateAttendeeDTO $attendeeDTO): AttendeeDomainObject TicketDomainObjectAbstract::EVENT_ID => $attendeeDTO->event_id, ]); + $ticketPriceId = $this->getTicketPriceId($attendeeDTO, $ticket); + $availableQuantity = $this->ticketRepository->getQuantityRemainingForTicketPrice( $attendeeDTO->ticket_id, - $attendeeDTO->ticket_price_id, + $ticketPriceId, ); if ($availableQuantity <= 0) { @@ -80,7 +82,6 @@ public function handle(CreateAttendeeDTO $attendeeDTO): AttendeeDomainObject ' please adjust the ticket\'s available quantity.')); } - $ticketPriceId = $this->getTicketPriceId($attendeeDTO, $ticket); $this->processTaxesAndFees($attendeeDTO); diff --git a/backend/app/Services/Handlers/Attendee/EditAttendeeHandler.php b/backend/app/Services/Handlers/Attendee/EditAttendeeHandler.php index 48f3d739..8fb87474 100644 --- a/backend/app/Services/Handlers/Attendee/EditAttendeeHandler.php +++ b/backend/app/Services/Handlers/Attendee/EditAttendeeHandler.php @@ -47,8 +47,8 @@ public function handle(EditAttendeeDTO $editAttendeeDTO): AttendeeDomainObject private function adjustTicketQuantities(AttendeeDomainObject $attendee, EditAttendeeDTO $editAttendeeDTO): void { if ($attendee->getTicketPriceId() !== $editAttendeeDTO->ticket_price_id) { - $this->ticketQuantityService->decreaseQuantitySold($editAttendeeDTO->ticket_price_id); - $this->ticketQuantityService->increaseQuantitySold($attendee->getTicketPriceId()); + $this->ticketQuantityService->decreaseQuantitySold($attendee->getTicketPriceId()); + $this->ticketQuantityService->increaseQuantitySold($editAttendeeDTO->ticket_price_id); } } @@ -59,6 +59,7 @@ private function updateAttendee(EditAttendeeDTO $editAttendeeDTO): AttendeeDomai 'last_name' => $editAttendeeDTO->last_name, 'email' => $editAttendeeDTO->email, 'ticket_id' => $editAttendeeDTO->ticket_id, + 'ticket_price_id' => $editAttendeeDTO->ticket_price_id, ], [ 'event_id' => $editAttendeeDTO->event_id, ]); @@ -82,6 +83,13 @@ private function validateTicketId(EditAttendeeDTO $editAttendeeDTO): void ]); } + $ticketPriceIds = $ticket->getTicketPrices()->map(fn($ticketPrice) => $ticketPrice->getId())->toArray(); + if (!in_array($editAttendeeDTO->ticket_price_id, $ticketPriceIds, true)) { + throw ValidationException::withMessages([ + 'ticket_price_id' => __('Ticket price ID is not valid'), + ]); + } + $availableQuantity = $this->ticketRepository->getQuantityRemainingForTicketPrice( ticketId: $editAttendeeDTO->ticket_id, ticketPriceId: $ticket->getType() === TicketType::TIERED->name diff --git a/frontend/src/components/modals/EditAttendeeModal/index.tsx b/frontend/src/components/modals/EditAttendeeModal/index.tsx index abc79158..ede92545 100644 --- a/frontend/src/components/modals/EditAttendeeModal/index.tsx +++ b/frontend/src/components/modals/EditAttendeeModal/index.tsx @@ -50,6 +50,18 @@ export const EditAttendeeModal = ({onClose, attendeeId}: EditAttendeeModalProps) }, [isFetched]); + useEffect(() => { + if (!form.values.ticket_id) { + return; + } + + let ticketPriceId = event?.tickets?.find(ticket => ticket.id == form.values.ticket_id)?.prices?.[0]?.id; + form.setValues({ + ...form.values, + ticket_price_id: String(ticketPriceId), + }); + }, [form.values.ticket_id]); + const handleSubmit = (values: EditAttendeeRequest) => { mutation.mutate({ attendeeId: attendeeId,