Skip to content

Commit

Permalink
Merge pull request #328 from HiEventsDev/develop
Browse files Browse the repository at this point in the history
main <- develop
  • Loading branch information
daveearley authored Dec 20, 2024
2 parents 6df23ed + 12efd7d commit 25fcdab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
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

0 comments on commit 25fcdab

Please sign in to comment.