All files / src/services registrationService.ts

62.5% Statements 5/8
100% Branches 2/2
33.33% Functions 1/3
62.5% Lines 5/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                                            3x     4x     2x               3x                         3x      
/**
 * Registration Service
 * Story 10.10: Registration Status Indicator for Logged-in Users (T7)
 *
 * Handles GET /events/{eventCode}/my-registration — authenticated user's registration status.
 * CRITICAL: Always use this service layer — never call apiClient directly from components.
 */
 
import apiClient from '@/services/api/apiClient';
import type { components } from '@/types/generated/event-registrations-api.types';
 
export type MyRegistrationResponse = components['schemas']['MyRegistrationResponse'];
 
/**
 * Fetch the authenticated user's registration status for an event.
 *
 * Returns null when the user has no registration (registered=false).
 * Returns the full response when registered=true.
 * Throws on non-2xx errors.
 *
 * @param eventCode Event code (e.g., "BATbern142")
 */
export const getMyRegistration = async (
  eventCode: string
): Promise<MyRegistrationResponse | null> => {
  const response = await apiClient.get<MyRegistrationResponse>(
    `/events/${eventCode}/my-registration`
  );
  return response.data.registered ? response.data : null;
};
 
/**
 * Quick registration for an authenticated attendee.
 * No form data required — profile is read from the JWT session on the server.
 * Returns the server message and the attendee's email.
 */
export const createMyRegistration = async (
  eventCode: string
): Promise<{ message: string; email: string }> => {
  const response = await apiClient.post<{ message: string; email: string }>(
    `/events/${eventCode}/my-registration`
  );
  return response.data;
};
 
/**
 * Immediately cancel the authenticated user's registration for an event.
 * No email is sent. Triggers waitlist promotion on the server.
 */
export const deleteMyRegistration = async (eventCode: string): Promise<void> => {
  await apiClient.delete(`/events/${eventCode}/my-registration`);
};