Skip to content
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
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace HiEvents\Http\Actions\Admin\Accounts;

use HiEvents\DomainObjects\Enums\Role;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Resources\Account\AdminAccountDetailResource;
use HiEvents\Services\Application\Handlers\Admin\GetAccountHandler;
use HiEvents\Services\Application\Handlers\Admin\UpdateAccountVerificationHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UpdateAccountVerificationAction extends BaseAction
{
public function __construct(
private readonly UpdateAccountVerificationHandler $handler,
private readonly GetAccountHandler $getAccountHandler,
) {}

public function __invoke(Request $request, int $accountId): JsonResponse
{
$this->minimumAllowedRole(Role::SUPERADMIN);

$validated = $request->validate([
'is_manually_verified' => 'required|boolean',
]);

$this->handler->handle($accountId, $validated['is_manually_verified']);

$account = $this->getAccountHandler->handle($accountId);

return $this->jsonResponse(new AdminAccountDetailResource($account), wrapInData: true);
}
}
28 changes: 28 additions & 0 deletions backend/app/Http/Actions/Events/Stats/GetEventCountsAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace HiEvents\Http\Actions\Events\Stats;

use HiEvents\DomainObjects\EventDomainObject;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Services\Domain\Event\EventCountsFetchService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\JsonResource;

class GetEventCountsAction extends BaseAction
{
public function __construct(
private readonly EventCountsFetchService $eventCountsFetchService,
) {}

public function __invoke(int $eventId): JsonResponse
{
$this->isActionAuthorized($eventId, EventDomainObject::class);

return $this->resourceResponse(
JsonResource::class,
$this->eventCountsFetchService->getEventCounts($eventId),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function toArray(Request $request): array
'email' => $this->resource->email,
'timezone' => $this->resource->timezone,
'currency_code' => $this->resource->currency_code,
'is_manually_verified' => (bool) $this->resource->is_manually_verified,
'created_at' => $this->resource->created_at,
'updated_at' => $this->resource->updated_at,
'events_count' => $this->resource->events_count ?? 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace HiEvents\Services\Application\Handlers\Admin;

use HiEvents\DomainObjects\AccountDomainObject;
use HiEvents\Repository\Interfaces\AccountRepositoryInterface;

class UpdateAccountVerificationHandler
{
public function __construct(
private readonly AccountRepositoryInterface $accountRepository,
) {}

public function handle(int $accountId, bool $isManuallyVerified): AccountDomainObject
{
return $this->accountRepository->updateFromArray($accountId, [
'is_manually_verified' => $isManuallyVerified,
]);
}
}
15 changes: 15 additions & 0 deletions backend/app/Services/Domain/Event/DTO/EventCountsResponseDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace HiEvents\Services\Domain\Event\DTO;

use HiEvents\DataTransferObjects\BaseDataObject;

class EventCountsResponseDTO extends BaseDataObject
{
public function __construct(
public readonly int $total_orders,
public readonly int $total_attendees_registered,
) {}
}
28 changes: 28 additions & 0 deletions backend/app/Services/Domain/Event/EventCountsFetchService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace HiEvents\Services\Domain\Event;

use HiEvents\DomainObjects\EventStatisticDomainObject;
use HiEvents\Repository\Interfaces\EventStatisticRepositoryInterface;
use HiEvents\Services\Domain\Event\DTO\EventCountsResponseDTO;

readonly class EventCountsFetchService
{
public function __construct(
private EventStatisticRepositoryInterface $eventStatisticRepository,
) {}

public function getEventCounts(int $eventId): EventCountsResponseDTO
{
$statistics = $this->eventStatisticRepository->findFirstWhere([
EventStatisticDomainObject::EVENT_ID => $eventId,
]);

return new EventCountsResponseDTO(
total_orders: $statistics?->getOrdersCreated() ?? 0,
total_attendees_registered: $statistics?->getAttendeesRegistered() ?? 0,
);
}
}
8 changes: 7 additions & 1 deletion backend/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use HiEvents\Http\Actions\Admin\Accounts\GetAccountAction as GetAdminAccountAction;
use HiEvents\Http\Actions\Admin\Accounts\GetAllAccountsAction as GetAllAdminAccountsAction;
use HiEvents\Http\Actions\Admin\Accounts\UpdateAccountMessagingTierAction;
use HiEvents\Http\Actions\Admin\Accounts\UpdateAccountVerificationAction;
use HiEvents\Http\Actions\Admin\Announcements\CreateAnnouncementAction;
use HiEvents\Http\Actions\Admin\Announcements\DeleteAnnouncementAction;
use HiEvents\Http\Actions\Admin\Announcements\GetAllAnnouncementsAction;
Expand Down Expand Up @@ -104,10 +105,10 @@
use HiEvents\Http\Actions\EventOccurrences\DeleteEventOccurrenceAction;
use HiEvents\Http\Actions\EventOccurrences\DeletePriceOverrideAction;
use HiEvents\Http\Actions\EventOccurrences\GenerateOccurrencesAction;
use HiEvents\Http\Actions\EventOccurrences\GetOccurrenceGenerationStatusAction;
use HiEvents\Http\Actions\EventOccurrences\GetEventOccurrenceAction;
use HiEvents\Http\Actions\EventOccurrences\GetEventOccurrencesAction;
use HiEvents\Http\Actions\EventOccurrences\GetEventOccurrencesPublicAction;
use HiEvents\Http\Actions\EventOccurrences\GetOccurrenceGenerationStatusAction;
use HiEvents\Http\Actions\EventOccurrences\GetPriceOverridesAction;
use HiEvents\Http\Actions\EventOccurrences\GetProductVisibilityAction;
use HiEvents\Http\Actions\EventOccurrences\ReactivateOccurrenceAction;
Expand All @@ -125,6 +126,7 @@
use HiEvents\Http\Actions\Events\Images\CreateEventImageAction;
use HiEvents\Http\Actions\Events\Images\DeleteEventImageAction;
use HiEvents\Http\Actions\Events\Images\GetEventImagesAction;
use HiEvents\Http\Actions\Events\Stats\GetEventCountsAction;
use HiEvents\Http\Actions\Events\Stats\GetEventStatsAction;
use HiEvents\Http\Actions\Events\UpdateEventAction;
use HiEvents\Http\Actions\Events\UpdateEventLocationAction;
Expand Down Expand Up @@ -406,6 +408,7 @@ function (Router $router): void {

// Stats
$router->get('/events/{event_id}/stats', GetEventStatsAction::class);
$router->get('/events/{event_id}/counts', GetEventCountsAction::class);

// Email Templates - Event level
$router->get('/events/{eventId}/email-templates', GetEventEmailTemplatesAction::class);
Expand Down Expand Up @@ -574,6 +577,9 @@ function (Router $router): void {
$router->get('/messaging-tiers', GetMessagingTiersAction::class);
$router->put('/accounts/{account_id}/messaging-tier', UpdateAccountMessagingTierAction::class);

// Account Verification
$router->put('/accounts/{account_id}/verification', UpdateAccountVerificationAction::class);

// Account Deletion Requests
$router->get('/deletion-requests', GetAllAccountDeletionRequestsAction::class);
$router->post('/accounts/{account_id}/deletion-request', AdminRequestAccountDeletionAction::class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace Tests\Unit\Services\Application\Handlers\Admin;

use HiEvents\DomainObjects\AccountDomainObject;
use HiEvents\Repository\Interfaces\AccountRepositoryInterface;
use HiEvents\Services\Application\Handlers\Admin\UpdateAccountVerificationHandler;
use Mockery;
use Mockery\MockInterface;
use Tests\TestCase;

class UpdateAccountVerificationHandlerTest extends TestCase
{
private AccountRepositoryInterface|MockInterface $accountRepository;

private UpdateAccountVerificationHandler $handler;

protected function setUp(): void
{
parent::setUp();

$this->accountRepository = Mockery::mock(AccountRepositoryInterface::class);
$this->handler = new UpdateAccountVerificationHandler($this->accountRepository);
}

public function test_it_marks_the_account_as_manually_verified(): void
{
$account = (new AccountDomainObject)->setId(42)->setIsManuallyVerified(true);

$this->accountRepository
->shouldReceive('updateFromArray')
->once()
->with(42, ['is_manually_verified' => true])
->andReturn($account);

$result = $this->handler->handle(42, true);

$this->assertTrue($result->getIsManuallyVerified());
}

public function test_it_revokes_manual_verification(): void
{
$account = (new AccountDomainObject)->setId(7)->setIsManuallyVerified(false);

$this->accountRepository
->shouldReceive('updateFromArray')
->once()
->with(7, ['is_manually_verified' => false])
->andReturn($account);

$result = $this->handler->handle(7, false);

$this->assertFalse($result->getIsManuallyVerified());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Tests\Unit\Services\Domain\Event;

use HiEvents\DomainObjects\EventStatisticDomainObject;
use HiEvents\Repository\Interfaces\EventStatisticRepositoryInterface;
use HiEvents\Services\Domain\Event\EventCountsFetchService;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Mockery as m;
use PHPUnit\Framework\TestCase;

class EventCountsFetchServiceTest extends TestCase
{
use MockeryPHPUnitIntegration;

private EventStatisticRepositoryInterface $repository;

private EventCountsFetchService $service;

protected function setUp(): void
{
parent::setUp();

$this->repository = m::mock(EventStatisticRepositoryInterface::class);
$this->service = new EventCountsFetchService($this->repository);
}

public function test_it_returns_the_lifetime_counts_for_the_event(): void
{
$statistics = (new EventStatisticDomainObject)
->setOrdersCreated(12)
->setAttendeesRegistered(31);

$this->repository
->shouldReceive('findFirstWhere')
->with([EventStatisticDomainObject::EVENT_ID => 5])
->once()
->andReturn($statistics);

$counts = $this->service->getEventCounts(5);

$this->assertSame(12, $counts->total_orders);
$this->assertSame(31, $counts->total_attendees_registered);
}

public function test_it_returns_zeros_when_the_event_has_no_statistics_row(): void
{
$this->repository
->shouldReceive('findFirstWhere')
->with([EventStatisticDomainObject::EVENT_ID => 9])
->once()
->andReturnNull();

$counts = $this->service->getEventCounts(9);

$this->assertSame(0, $counts->total_orders);
$this->assertSame(0, $counts->total_attendees_registered);
}
}
22 changes: 22 additions & 0 deletions e2e/api/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,28 @@ export class AdminApiClient {
);
}

setAccountVerification(accountId: number, isManuallyVerified: boolean): Promise<void> {
return check(
this.request.put(`admin/accounts/${accountId}/verification`, {
headers: jsonHeaders,
data: { is_manually_verified: isManuallyVerified },
}),
);
}

async findAccountIdByEmail(email: string): Promise<number> {
const accounts = await unwrap<{ id: number; email: string }[]>(
this.request.get('admin/accounts', { headers: jsonHeaders, params: { search: email } }),
);

const match = accounts.find((account) => account.email === email);
if (!match) {
throw new Error(`No admin account found for ${email}`);
}

return match.id;
}

createAnnouncement(payload: UpsertAnnouncementPayload): Promise<{ id: number }> {
return unwrap(this.request.post('admin/announcements', { headers: jsonHeaders, data: payload }));
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/api/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,11 @@ export async function createCompletedPaidOrder(
publicApi: APIRequestContext,
event: Pick<SeededEvent, 'eventId' | 'productId' | 'priceId'>,
opts: OrderSeedOptions = {},
): Promise<SeededOrder & { orderId: number }> {
): Promise<SeededOrder & { orderId: number; totalGross: number }> {
const seeded = await createAwaitingOfflineOrder(api, publicApi, event, opts);
await api.markOrderAsPaid(event.eventId, seeded.orderId);
const completed = await getPublicOrder(publicApi, event.eventId, seeded.orderShortId, seeded.sessionId);
return { ...seeded, attendees: mapAttendees(completed) };
return { ...seeded, attendees: mapAttendees(completed), totalGross: completed.total_gross };
}

export async function createSoldOutEvent(
Expand Down
Loading
Loading