feat(roster): define API types and client methods for workshop rosters
This commit is contained in:
1 parent
00b59182ac
commit
0ff27a2038
2 files changed
+111
No files matched your search
+61
@@ -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<RosterSession[]> {
|
||||
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<QuickCheckinResponse> {
|
||||
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();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user