mirror of
http://88.130.71.182:3000/BlitTech/badoHair_fe.git
synced 2026-06-13 11:03:02 +00:00
Update May 12 by Elvis
This commit is contained in:
143
lib/api/bookings.ts
Normal file
143
lib/api/bookings.ts
Normal file
@@ -0,0 +1,143 @@
|
||||
import { api, PaginatedResult } from "@/lib/api";
|
||||
|
||||
export interface TimeSlotApi {
|
||||
id: string;
|
||||
date: string;
|
||||
start_time: string;
|
||||
end_time: string;
|
||||
is_blocked: boolean;
|
||||
is_booked: boolean;
|
||||
}
|
||||
|
||||
export interface BookingApi {
|
||||
id: string;
|
||||
user_id: string | null;
|
||||
slot_id: string;
|
||||
slot_date: string;
|
||||
slot_start: string;
|
||||
slot_end: string;
|
||||
service_note: string | null;
|
||||
client_name: string | null;
|
||||
client_email: string | null;
|
||||
client_phone: string | null;
|
||||
status: "pending" | "confirmed" | "cancelled" | "completed" | "no_show";
|
||||
amount_paid: number | null;
|
||||
stripe_payment_intent_id: string | null;
|
||||
admin_notes: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface CreateBookingPayload {
|
||||
slot_id: string;
|
||||
service_note?: string;
|
||||
guest_name?: string;
|
||||
guest_email?: string;
|
||||
guest_phone?: string;
|
||||
}
|
||||
|
||||
export interface BookingResult {
|
||||
booking_id: string;
|
||||
}
|
||||
|
||||
export async function getAvailableSlots(
|
||||
from_date: string,
|
||||
to_date: string
|
||||
): Promise<TimeSlotApi[]> {
|
||||
return api.get<TimeSlotApi[]>(
|
||||
`/bookings/slots?from_date=${from_date}&to_date=${to_date}`
|
||||
);
|
||||
}
|
||||
|
||||
export async function createBooking(payload: CreateBookingPayload): Promise<BookingResult> {
|
||||
return api.post<BookingResult>("/bookings", payload);
|
||||
}
|
||||
|
||||
export async function listMyBookings(): Promise<PaginatedResult<BookingApi>> {
|
||||
return api.get<PaginatedResult<BookingApi>>("/bookings");
|
||||
}
|
||||
|
||||
export async function cancelBooking(id: string): Promise<void> {
|
||||
await api.del(`/bookings/${id}`);
|
||||
}
|
||||
|
||||
// ── Admin — Schedule ──────────────────────────────────────────────────────────
|
||||
|
||||
export interface WeeklySchedule {
|
||||
id: string;
|
||||
day_of_week: number; // 0=Monday, 6=Sunday
|
||||
start_time: string;
|
||||
end_time: string;
|
||||
slot_duration_minutes: number;
|
||||
is_active: boolean;
|
||||
}
|
||||
|
||||
export interface BlockedDate {
|
||||
id: string;
|
||||
date: string;
|
||||
reason: string | null;
|
||||
}
|
||||
|
||||
export async function adminGetSchedule(): Promise<WeeklySchedule[]> {
|
||||
return api.get<WeeklySchedule[]>("/admin/schedule");
|
||||
}
|
||||
|
||||
export async function adminCreateSchedule(payload: {
|
||||
day_of_week: number;
|
||||
start_time: string;
|
||||
end_time: string;
|
||||
slot_duration_minutes: number;
|
||||
}): Promise<WeeklySchedule> {
|
||||
return api.post<WeeklySchedule>("/admin/schedule", payload);
|
||||
}
|
||||
|
||||
export async function adminDeleteSchedule(id: string): Promise<void> {
|
||||
await api.del(`/admin/schedule/${id}`);
|
||||
}
|
||||
|
||||
export async function adminListSlots(from_date: string, to_date: string): Promise<TimeSlotApi[]> {
|
||||
return api.get<TimeSlotApi[]>(`/admin/slots?from_date=${from_date}&to_date=${to_date}`);
|
||||
}
|
||||
|
||||
export async function adminGenerateSlots(from_date: string, to_date: string): Promise<{ created: number }> {
|
||||
return api.post<{ created: number }>("/admin/slots/generate", { from_date, to_date });
|
||||
}
|
||||
|
||||
export async function adminUpdateSlot(id: string, is_blocked: boolean, block_reason?: string): Promise<TimeSlotApi> {
|
||||
return api.patch<TimeSlotApi>(`/admin/slots/${id}`, { is_blocked, block_reason });
|
||||
}
|
||||
|
||||
export async function adminDeleteSlot(id: string): Promise<void> {
|
||||
await api.del(`/admin/slots/${id}`);
|
||||
}
|
||||
|
||||
export async function adminGetBlockedDates(): Promise<BlockedDate[]> {
|
||||
return api.get<BlockedDate[]>("/admin/blocked-dates");
|
||||
}
|
||||
|
||||
export async function adminAddBlockedDate(date: string, reason?: string): Promise<BlockedDate> {
|
||||
return api.post<BlockedDate>("/admin/blocked-dates", { date, reason });
|
||||
}
|
||||
|
||||
export async function adminRemoveBlockedDate(id: string): Promise<void> {
|
||||
await api.del(`/admin/blocked-dates/${id}`);
|
||||
}
|
||||
|
||||
// ── Admin — Bookings ──────────────────────────────────────────────────────────
|
||||
|
||||
export async function adminListBookings(
|
||||
status?: string
|
||||
): Promise<PaginatedResult<BookingApi>> {
|
||||
const qs = status ? `?status=${status}&per_page=100` : "?per_page=100";
|
||||
return api.get<PaginatedResult<BookingApi>>(`/admin/bookings${qs}`);
|
||||
}
|
||||
|
||||
export async function adminUpdateBookingStatus(
|
||||
id: string,
|
||||
status: string
|
||||
): Promise<BookingApi> {
|
||||
return api.patch<BookingApi>(`/admin/bookings/${id}`, { status });
|
||||
}
|
||||
|
||||
export async function adminDeleteBooking(id: string): Promise<void> {
|
||||
await api.del(`/admin/bookings/${id}`);
|
||||
}
|
||||
Reference in New Issue
Block a user