All files / src/services deregistrationService.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 3/3
100% Lines 4/4

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                                                          3x     2x         2x         1x          
/**
 * Deregistration Service (Story 10.12)
 *
 * HTTP client for self-service deregistration APIs.
 */
 
import apiClient from '@/services/api/apiClient';
 
export interface DeregistrationVerifyResponse {
  registrationCode: string;
  eventCode: string;
  eventTitle: string;
  eventDate: string;
  attendeeFirstName: string;
}
 
export interface DeregistrationRequest {
  token: string;
}
 
export interface DeregistrationByEmailRequest {
  email: string;
  eventCode: string;
}
 
/** Verify a deregistration token — returns registration details if valid. Throws 404 if invalid or already cancelled. */
export async function verifyDeregistrationToken(
  token: string
): Promise<DeregistrationVerifyResponse> {
  const response = await apiClient.get<DeregistrationVerifyResponse>(
    `/registrations/deregister/verify?token=${encodeURIComponent(token)}`
  );
  return response.data;
}
 
/** Cancel registration using deregistration token. Throws 404 if invalid, 409 if already cancelled. */
export async function deregisterByToken(token: string): Promise<void> {
  await apiClient.post('/registrations/deregister', { token } as DeregistrationRequest);
}
 
/** Request deregistration link via email (always returns 200 — anti-enumeration). */
export async function deregisterByEmail(email: string, eventCode: string): Promise<void> {
  await apiClient.post('/registrations/deregister/by-email', {
    email,
    eventCode,
  } as DeregistrationByEmailRequest);
}