All files / src/services thanksService.ts

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

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 54 55                                                                                                             
/**
 * Thanks Service (Story 7.4 — "Thank the Organizers")
 *
 * HTTP client for the public "thank the organizers" endpoints. Submit is anonymous-allowed and
 * Turnstile-guarded (token via X-Turnstile-Token header, mirroring the newsletter widget); the
 * GET returns the public aggregate count (organizer callers additionally receive notes).
 */
 
import apiClient from '@/services/api/apiClient';
import type { components } from '@/types/generated/events-core-api.types';
 
export type ThanksCountResponse = components['schemas']['ThanksCountResponse'];
export type ThanksNoteResponse = components['schemas']['ThanksNoteResponse'];
 
/**
 * Organizer feature-toggle (Story 7.7): mark/un-mark a thank-you note for the public marquee.
 * Organizer-authenticated; featuring an anonymous note is rejected server-side (409).
 */
export async function setThanksFeatured(
  eventCode: string,
  id: string,
  featured: boolean
): Promise<ThanksNoteResponse> {
  const response = await apiClient.patch<ThanksNoteResponse>(
    `/events/${encodeURIComponent(eventCode)}/thanks/${encodeURIComponent(id)}`,
    { featured }
  );
  return response.data;
}
 
/**
 * Submit a thank-you for an event (no auth required). Returns the new aggregate count.
 * @param turnstileToken Optional Cloudflare Turnstile token — passed via X-Turnstile-Token when present.
 */
export async function submitThanks(
  eventCode: string,
  note?: string | null,
  turnstileToken?: string | null
): Promise<ThanksCountResponse> {
  const response = await apiClient.post<ThanksCountResponse>(
    `/events/${encodeURIComponent(eventCode)}/thanks`,
    note ? { note } : {},
    { headers: turnstileToken ? { 'X-Turnstile-Token': turnstileToken } : {} }
  );
  return response.data;
}
 
/** Get the public aggregate thank-you count for an event. */
export async function getThanks(eventCode: string): Promise<ThanksCountResponse> {
  const response = await apiClient.get<ThanksCountResponse>(
    `/events/${encodeURIComponent(eventCode)}/thanks`
  );
  return response.data;
}