Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

Fix some attendees not being found when using QR checkin (#507)

Dave Earley43a416f4fec4
diff --git a/backend/app/Http/Actions/CheckInLists/Public/GetCheckInListAttendeePublicAction.php b/backend/app/Http/Actions/CheckInLists/Public/GetCheckInListAttendeePublicAction.php
new file mode 100644
index 000000000..d9d895186
--- /dev/null
+++ b/backend/app/Http/Actions/CheckInLists/Public/GetCheckInListAttendeePublicAction.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace HiEvents\Http\Actions\CheckInLists\Public;
+
+use HiEvents\Exceptions\CannotCheckInException;
+use HiEvents\Http\Actions\BaseAction;
+use HiEvents\Resources\Attendee\AttendeeWithCheckInPublicResource;
+use HiEvents\Services\Application\Handlers\CheckInList\Public\GetCheckInListAttendeePublicHandler;
+use Illuminate\Http\JsonResponse;
+use Illuminate\Http\Request;
+use Symfony\Component\HttpFoundation\Response;
+
+class GetCheckInListAttendeePublicAction extends BaseAction
+{
+ public function __construct(
+ private readonly GetCheckInListAttendeePublicHandler $getCheckInListAttendeePublicHandler,
+ )
+ {
+ }
+
+ public function __invoke(string $shortId, string $attendeePublicId, Request $request): JsonResponse
+ {
+ try {
+ $attendee = $this->getCheckInListAttendeePublicHandler->handle(
+ shortId: $shortId,
+ attendeePublicId: $attendeePublicId,
+ );
+ } catch (CannotCheckInException $e) {
+ return $this->errorResponse(
+ message: $e->getMessage(),
+ statusCode: Response::HTTP_FORBIDDEN,
+ );
+ }
+
+ return $this->resourceResponse(
+ resource: AttendeeWithCheckInPublicResource::class,
+ data: $attendee,
+ );
+ }
+}
diff --git a/backend/app/Repository/Eloquent/AttendeeRepository.php b/backend/app/Repository/Eloquent/AttendeeRepository.php
index ed62a3728..92df6f4d9 100644
--- a/backend/app/Repository/Eloquent/AttendeeRepository.php
+++ b/backend/app/Repository/Eloquent/AttendeeRepository.php
@@ -118,7 +118,7 @@ class AttendeeRepository extends BaseRepository implements AttendeeRepositoryInt
return $this->simplePaginateWhere(
where: $where,
- limit: 100,
+ limit: min($params->per_page, 250),
);
}
}
diff --git a/backend/app/Repository/Eloquent/BaseRepository.php b/backend/app/Repository/Eloquent/BaseRepository.php
index aa174bd99..865ccd37d 100644
--- a/backend/app/Repository/Eloquent/BaseRepository.php
+++ b/backend/app/Repository/Eloquent/BaseRepository.php
@@ -99,7 +99,7 @@ abstract class BaseRepository implements RepositoryInterface
public function simplePaginateWhere(
array $where,
- ?int $limit = null,
+ ?int $limit = null,
array $columns = self::DEFAULT_COLUMNS,
): Paginator
{
@@ -131,9 +131,9 @@ abstract class BaseRepository implements RepositoryInterface
}
public function findFirstByField(
- string $field,
+ string $field,
?string $value = null,
- array $columns = ['*']
+ array $columns = ['*']
): ?DomainObjectInterface
{
$model = $this->model->where($field, '=', $value)->first($columns);
diff --git a/backend/app/Services/Application/Handlers/CheckInList/Public/GetCheckInListAttendeePublicHandler.php b/backend/app/Services/Application/Handlers/CheckInList/Public/GetCheckInListAttendeePublicHandler.php
new file mode 100644
index 000000000..5879b0885
--- /dev/null
+++ b/backend/app/Services/Application/Handlers/CheckInList/Public/GetCheckInListAttendeePublicHandler.php
@@ -0,0 +1,64 @@
+<?php
+
+namespace HiEvents\Services\Application\Handlers\CheckInList\Public;
+
+use HiEvents\DomainObjects\AttendeeDomainObject;
+use HiEvents\DomainObjects\CheckInListDomainObject;
+use HiEvents\DomainObjects\EventDomainObject;
+use HiEvents\DomainObjects\Generated\CheckInListDomainObjectAbstract;
+use HiEvents\DomainObjects\ProductDomainObject;
+use HiEvents\Exceptions\CannotCheckInException;
+use HiEvents\Helper\DateHelper;
+use HiEvents\Repository\Eloquent\Value\Relationship;
+use HiEvents\Repository\Interfaces\AttendeeRepositoryInterface;
+use HiEvents\Repository\Interfaces\CheckInListRepositoryInterface;
+use Symfony\Component\Routing\Exception\ResourceNotFoundException;
+
+class GetCheckInListAttendeePublicHandler
+{
+ public function __construct(
+ private readonly AttendeeRepositoryInterface $attendeeRepository,
+ private readonly CheckInListRepositoryInterface $checkInListRepository,
+ )
+ {
+ }
+
+ /**
+ * @throws CannotCheckInException
+ */
+ public function handle(string $shortId, string $attendeePublicId): AttendeeDomainObject
+ {
+ $checkInList = $this->checkInListRepository
+ ->loadRelation(ProductDomainObject::class)
+ ->loadRelation(new Relationship(EventDomainObject::class, name: 'event'))
+ ->findFirstWhere([
+ CheckInListDomainObjectAbstract::SHORT_ID => $shortId,
+ ]);
+
+ if (!$checkInList) {
+ throw new ResourceNotFoundException(__('Check-in list not found'));
+ }
+
+ $this->validateCheckInListIsActive($checkInList);
+
+ return $this->attendeeRepository->findFirstWhere([
+ 'public_id' => $attendeePublicId,
+ 'event_id' => $checkInList->getEventId(),
+ ]);
+ }
+
+ /**
+ * @todo - Move this to its own service. It's used 3 times
+ * @throws CannotCheckInException
+ */
+ private function validateCheckInListIsActive(CheckInListDomainObject $checkInList): void
+ {
+ if ($checkInList->getExpiresAt() && DateHelper::utcDateIsPast($checkInList->getExpiresAt())) {
+ throw new CannotCheckInException(__('Check-in list has expired'));
+ }
+
+ if ($checkInList->getActivatesAt() && DateHelper::utcDateIsFuture($checkInList->getActivatesAt())) {
+ throw new CannotCheckInException(__('Check-in list is not active yet'));
+ }
+ }
+}
diff --git a/backend/routes/api.php b/backend/routes/api.php
index fce8aff88..b684be9e5 100644
--- a/backend/routes/api.php
+++ b/backend/routes/api.php
@@ -32,6 +32,7 @@ use HiEvents\Http\Actions\CheckInLists\GetCheckInListAction;
use HiEvents\Http\Actions\CheckInLists\GetCheckInListsAction;
use HiEvents\Http\Actions\CheckInLists\Public\CreateAttendeeCheckInPublicAction;
use HiEvents\Http\Actions\CheckInLists\Public\DeleteAttendeeCheckInPublicAction;
+use HiEvents\Http\Actions\CheckInLists\Public\GetCheckInListAttendeePublicAction;
use HiEvents\Http\Actions\CheckInLists\Public\GetCheckInListAttendeesPublicAction;
use HiEvents\Http\Actions\CheckInLists\Public\GetCheckInListPublicAction;
use HiEvents\Http\Actions\CheckInLists\UpdateCheckInListAction;
@@ -340,6 +341,7 @@ $router->prefix('/public')->group(
// Check-In
$router->get('/check-in-lists/{check_in_list_short_id}', GetCheckInListPublicAction::class);
$router->get('/check-in-lists/{check_in_list_short_id}/attendees', GetCheckInListAttendeesPublicAction::class);
+ $router->get('/check-in-lists/{check_in_list_short_id}/attendees/{attendee_public_id}', GetCheckInListAttendeePublicAction::class);
$router->post('/check-in-lists/{check_in_list_short_id}/check-ins', CreateAttendeeCheckInPublicAction::class);
$router->delete('/check-in-lists/{check_in_list_short_id}/check-ins/{check_in_short_id}', DeleteAttendeeCheckInPublicAction::class);
}
diff --git a/backend/tests/Unit/Services/Application/Handlers/CheckInList/Public/GetCheckInListAttendeePublicHandlerTest.php b/backend/tests/Unit/Services/Application/Handlers/CheckInList/Public/GetCheckInListAttendeePublicHandlerTest.php
new file mode 100644
index 000000000..d07cf0bae
--- /dev/null
+++ b/backend/tests/Unit/Services/Application/Handlers/CheckInList/Public/GetCheckInListAttendeePublicHandlerTest.php
@@ -0,0 +1,124 @@
+<?php
+
+namespace Tests\Unit\Services\Application\Handlers\CheckInList\Public;
+
+use HiEvents\DomainObjects\AttendeeDomainObject;
+use HiEvents\DomainObjects\CheckInListDomainObject;
+use HiEvents\Exceptions\CannotCheckInException;
+use HiEvents\Repository\Interfaces\AttendeeRepositoryInterface;
+use HiEvents\Repository\Interfaces\CheckInListRepositoryInterface;
+use HiEvents\Services\Application\Handlers\CheckInList\Public\GetCheckInListAttendeePublicHandler;
+use Mockery as m;
+use Symfony\Component\Routing\Exception\ResourceNotFoundException;
+use Tests\TestCase;
+
+class GetCheckInListAttendeePublicHandlerTest extends TestCase
+{
+ private CheckInListRepositoryInterface $checkInListRepository;
+ private AttendeeRepositoryInterface $attendeeRepository;
+ private GetCheckInListAttendeePublicHandler $handler;
+
+ protected function setUp(): void
+ {
+ parent::setUp();
+
+ $this->checkInListRepository = m::mock(CheckInListRepositoryInterface::class);
+ $this->attendeeRepository = m::mock(AttendeeRepositoryInterface::class);
+
+ $this->handler = new GetCheckInListAttendeePublicHandler(
+ $this->attendeeRepository,
+ $this->checkInListRepository
+ );
+ }
+
+ public function testHandleThrowsNotFoundIfCheckInListMissing(): void
+ {
+ $this->checkInListRepository
+ ->shouldReceive('loadRelation')
+ ->andReturnSelf()
+ ->times(2);
+
+ $this->checkInListRepository
+ ->shouldReceive('findFirstWhere')
+ ->once()
+ ->andReturnNull();
+
+ $this->expectException(ResourceNotFoundException::class);
+
+ $this->handler->handle('short-id', 'attendee-public-id');
+ }
+
+ public function testHandleThrowsCannotCheckInIfListExpired(): void
+ {
+ $checkInList = m::mock(CheckInListDomainObject::class);
+ $checkInList->shouldReceive('getExpiresAt')->twice()->andReturn(now()->subMinute());
+
+ $this->checkInListRepository
+ ->shouldReceive('loadRelation')
+ ->andReturnSelf()
+ ->times(2);
+
+ $this->checkInListRepository
+ ->shouldReceive('findFirstWhere')
+ ->once()
+ ->andReturn($checkInList);
+
+ $this->expectException(CannotCheckInException::class);
+
+ $this->handler->handle('short-id', 'attendee-public-id');
+ }
+
+ public function testHandleThrowsCannotCheckInIfListNotActiveYet(): void
+ {
+ $checkInList = m::mock(CheckInListDomainObject::class);
+ $checkInList->shouldReceive('getExpiresAt')->once()->andReturn(null);
+ $checkInList->shouldReceive('getActivatesAt')->twice()->andReturn(now()->addMinute());
+
+ $this->checkInListRepository
+ ->shouldReceive('loadRelation')
+ ->andReturnSelf()
+ ->times(2);
+
+ $this->checkInListRepository
+ ->shouldReceive('findFirstWhere')
+ ->once()
+ ->andReturn($checkInList);
+
+ $this->expectException(CannotCheckInException::class);
+
+ $this->handler->handle('short-id', 'attendee-public-id');
+ }
+
+ public function testHandleReturnsAttendeeSuccessfully(): void
+ {
+ $checkInList = m::mock(CheckInListDomainObject::class);
+ $checkInList->shouldReceive('getExpiresAt')->once()->andReturn(null);
+ $checkInList->shouldReceive('getActivatesAt')->once()->andReturn(null);
+ $checkInList->shouldReceive('getEventId')->once()->andReturn(123);
+
+ $attendee = m::mock(AttendeeDomainObject::class);
+
+ $this->checkInListRepository
+ ->shouldReceive('loadRelation')
+ ->andReturnSelf()
+ ->times(2);
+
+ $this->checkInListRepository
+ ->shouldReceive('findFirstWhere')
+ ->once()
+ ->andReturn($checkInList);
+
+ $this->attendeeRepository
+ ->shouldReceive('findFirstWhere')
+ ->once()
+ ->with([
+ 'public_id' => 'attendee-public-id',
+ 'event_id' => 123,
+ ])
+ ->andReturn($attendee);
+
+ $result = $this->handler->handle('short-id', 'attendee-public-id');
+
+ $this->assertSame($attendee, $result);
+ }
+}
diff --git a/frontend/src/api/check-in.client.ts b/frontend/src/api/check-in.client.ts
index 93003796b..709121e91 100644
--- a/frontend/src/api/check-in.client.ts
+++ b/frontend/src/api/check-in.client.ts
@@ -18,6 +18,10 @@ export const publicCheckInClient = {
const response = await publicApi.get<GenericPaginatedResponse<Attendee>>(`/check-in-lists/${checkInListShortId}/attendees` + queryParamsHelper.buildQueryString(pagination));
return response.data;
},
+ getCheckInListAttendee: async (checkInListShortId: IdParam, attendeePublicId: IdParam) => {
+ const response = await publicApi.get<GenericDataResponse<Attendee>>(`/check-in-lists/${checkInListShortId}/attendees/${attendeePublicId}`);
+ return response.data;
+ },
createCheckIn: async (checkInListShortId: IdParam, attendeePublicId: IdParam, action: 'check-in' | 'check-in-and-mark-order-as-paid') => {
const response = await publicApi.post<GenericDataResponse<PublicCheckIn[]>>(`/check-in-lists/${checkInListShortId}/check-ins`, {
"attendees": [
diff --git a/frontend/src/components/layouts/CheckIn/index.tsx b/frontend/src/components/layouts/CheckIn/index.tsx
index bc0bb322c..c2cdd4217 100644
--- a/frontend/src/components/layouts/CheckIn/index.tsx
+++ b/frontend/src/components/layouts/CheckIn/index.tsx
@@ -25,6 +25,7 @@ import {NoResultsSplash} from "../../common/NoResultsSplash";
import {Countdown} from "../../common/Countdown";
import Truncate from "../../common/Truncate";
import {Header} from "../../common/Header";
+import {publicCheckInClient} from "../../../api/check-in.client.ts";
const CheckIn = () => {
const networkStatus = useNetwork();
@@ -49,7 +50,7 @@ const CheckIn = () => {
const queryFilters: QueryFilters = {
pageNumber: 1,
query: searchQueryDebounced,
- perPage: 100,
+ perPage: 150,
filterFields: {
status: {operator: 'eq', value: 'ACTIVE'},
},
@@ -134,11 +135,21 @@ const CheckIn = () => {
const handleQrCheckIn = async (attendeePublicId: string) => {
// Find the attendee in the current list or fetch them
- const attendee = attendees?.find(a => a.public_id === attendeePublicId);
+ let attendee = attendees?.find(a => a.public_id === attendeePublicId);
if (!attendee) {
- showError(t`Attendee not found`);
- return;
+ try {
+ const {data} = await publicCheckInClient.getCheckInListAttendee(checkInListShortId, attendeePublicId);
+ attendee = data;
+ } catch (error) {
+ showError(t`Unable to fetch attendee`);
+ return;
+ }
+
+ if (!attendee) {
+ showError(t`Attendee not found`);
+ return;
+ }
}
const isAttendeeAwaitingPayment = attendee.status === 'AWAITING_PAYMENT';
diff --git a/frontend/src/queries/useGetCheckInListAttendeePublic.ts b/frontend/src/queries/useGetCheckInListAttendeePublic.ts
new file mode 100644
index 000000000..17a35d3d0
--- /dev/null
+++ b/frontend/src/queries/useGetCheckInListAttendeePublic.ts
@@ -0,0 +1,14 @@
+import {useQuery} from '@tanstack/react-query';
+import {Attendee, GenericPaginatedResponse, IdParam} from '../types';
+import {publicCheckInClient} from "../api/check-in.client";
+
+export const GET_CHECK_IN_LIST_ATTENDEE_PUBLIC_QUERY_KEY = 'getCheckInListAttendee';
+
+export const useGetCheckInListAttendee = (checkInListShortId: IdParam, attendeePublicId: IdParam) => {
+ return useQuery<GenericPaginatedResponse<Attendee>>({
+ queryKey: [GET_CHECK_IN_LIST_ATTENDEE_PUBLIC_QUERY_KEY, checkInListShortId, attendeePublicId],
+ queryFn: async () => {
+ return await publicCheckInClient.getCheckInListAttendee(checkInListShortId, attendeePublicId);
+ },
+ });
+};
diff --git a/frontend/src/queries/useGetCheckInListAttendeesPublic.ts b/frontend/src/queries/useGetCheckInListAttendeesPublic.ts
index 7cfbc6de6..4c7c01b27 100644
--- a/frontend/src/queries/useGetCheckInListAttendeesPublic.ts
+++ b/frontend/src/queries/useGetCheckInListAttendeesPublic.ts
@@ -8,8 +8,7 @@ export const useGetCheckInListAttendees = (checkInListShortId: IdParam, paginati
return useQuery<GenericPaginatedResponse<Attendee>>({
queryKey: [GET_CHECK_IN_LIST_ATTENDEES_PUBLIC_QUERY_KEY, checkInListShortId, pagination],
queryFn: async () => {
- const data = await publicCheckInClient.getCheckInListAttendees(checkInListShortId, pagination);
- return data;
+ return await publicCheckInClient.getCheckInListAttendees(checkInListShortId, pagination);
},
enabled: enabled,
});