Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Capacity Assignment bugs related to creating and editing attendees #327

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);

Expand Down
12 changes: 10 additions & 2 deletions backend/app/Services/Handlers/Attendee/EditAttendeeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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,
]);
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/components/modals/EditAttendeeModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading