From 0ff27a203867f7c9e4bb3c037cd4eb8cbcd6b0f0 Mon Sep 17 00:00:00 2001 From: Anne Droid Date: Mon, 26 Oct 2026 09:41:45 -0500 Subject: [PATCH] feat(roster): define API types and client methods for workshop rosters --- src/api.ts | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/types.ts | 50 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) diff --git a/src/api.ts b/src/api.ts index 85c7c86..35f203a 100644 --- a/src/api.ts +++ b/src/api.ts @@ -10,6 +10,9 @@ import type { PackageRecord, PaymentAcknowledgmentPayload, PaymentRecord, + QuickCheckinPayload, + QuickCheckinResponse, + RosterSession, Service, } from "./types"; @@ -285,3 +288,61 @@ export async function fetchPackages( } return res.json(); } + +export class ApiError extends Error { + public status: number; + public detail?: string; + + constructor(status: number, message: string, detail?: string) { + super(message); + this.name = "ApiError"; + this.status = status; + this.detail = detail; + } +} + +export async function fetchRosters(params: { + date_from: string; + date_to: string; + service_id?: string; +}): Promise { + const query = new URLSearchParams(); + query.set("date_from", params.date_from); + query.set("date_to", params.date_to); + if (params.service_id) query.set("service_id", params.service_id); + + const url = `${API_BASE_URL}/rosters?${query.toString()}`; + const res = await fetch(url, { + headers: getAuthHeaders(), + }); + if (!res.ok) { + const errData = await res.json().catch(() => ({})); + const detail = errData.detail || `${res.status} ${res.statusText}`; + throw new ApiError( + res.status, + `Error al obtener talleres: ${detail}`, + errData.detail, + ); + } + return res.json(); +} + +export async function quickCheckin( + payload: QuickCheckinPayload, +): Promise { + const res = await fetch(`${API_BASE_URL}/rosters/quick-checkin`, { + method: "POST", + headers: getAuthHeaders(), + body: JSON.stringify(payload), + }); + if (!res.ok) { + const errData = await res.json().catch(() => ({})); + const detail = errData.detail || `${res.status} ${res.statusText}`; + throw new ApiError( + res.status, + `Error al registrar asistencia: ${detail}`, + errData.detail, + ); + } + return res.json(); +} diff --git a/src/types.ts b/src/types.ts index 5d8ae24..06915d0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -159,3 +159,53 @@ export interface BookingCompletePayload { package_id?: string | null; notes?: string | null; } + +export interface RosterAttendee { + booking_id: string; + booking_code: string; + client_id: string; + client_name: string; + client_phone: string; + client_email?: string | null; + booking_status: BookingStatus | string; + payment_arrangement: PaymentArrangement | string; + payment_status: PaymentStatus | string; + amount_mxn: number; + attended: boolean; +} + +export interface RosterSession { + service_id: string; + service_name: string; + scheduled_at: string; + max_capacity: number; + occupied_count: number; + attended_count: number; + attendees: RosterAttendee[]; +} + +export interface QuickCheckinBookingPayload { + booking_id: string; + paid_cash?: boolean; + notes?: string | null; +} + +export interface QuickCheckinWalkInPayload { + service_id: string; + scheduled_at: string; + client_name: string; + client_phone: string; + client_email?: string | null; + paid_cash?: boolean; + notes?: string | null; +} + +export type QuickCheckinPayload = + | QuickCheckinBookingPayload + | QuickCheckinWalkInPayload; + +export interface QuickCheckinResponse { + walk_in: boolean; + attendee: RosterAttendee; + payment_id?: string | null; +}