- Added cancelPublicBooking handler to manage booking cancellations. - Updated public booking service to include cancellation logic. - Created cancelPublicBooking schema for input validation. - Modified public booking confirmation page to allow users to cancel their bookings. - Enhanced email service to send cancellation confirmation emails. - Made customerEmail field required in booking schemas and updated related components. - Updated API client to support cancellation requests. - Added migration to enforce non-nullable customer_email fields in the database.
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import type {
|
|
AdminBooking,
|
|
CancelPublicBookingInput,
|
|
CreateAdminBookingInput,
|
|
CreatePublicBookingInput,
|
|
PublicAvailabilityResponse,
|
|
PublicBooking,
|
|
PublicBookingConfirmation,
|
|
UpdateAdminBookingStatusInput,
|
|
} from '@repo/api-contract';
|
|
import { http } from '../http';
|
|
|
|
export async function getAvailability(
|
|
complexSlug: string,
|
|
params: { date: string; sportId?: string }
|
|
) {
|
|
const response = await http.get<PublicAvailabilityResponse>(
|
|
`/api/public-bookings/complex/${complexSlug}/availability`,
|
|
{ params }
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function createPublic(complexSlug: string, payload: CreatePublicBookingInput) {
|
|
const response = await http.post<PublicBooking>(
|
|
`/api/public-bookings/complex/${complexSlug}`,
|
|
payload
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function getConfirmation(complexSlug: string, bookingCode: string) {
|
|
const response = await http.get<PublicBookingConfirmation>(
|
|
`/api/public-bookings/complex/${complexSlug}/confirmation/${bookingCode}`
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function listByComplex(complexId: string, params: { fromDate: string }) {
|
|
const response = await http.get<{ bookings: AdminBooking[] }>(
|
|
`/api/admin-bookings/complex/${complexId}`,
|
|
{ params }
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function createAdmin(complexId: string, payload: CreateAdminBookingInput) {
|
|
const response = await http.post<AdminBooking>(
|
|
`/api/admin-bookings/complex/${complexId}`,
|
|
payload
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function cancelPublic(complexSlug: string, payload: CancelPublicBookingInput) {
|
|
const response = await http.post<PublicBooking>(
|
|
`/api/public-bookings/complex/${complexSlug}/cancel`,
|
|
payload
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function updateStatus(bookingId: string, payload: UpdateAdminBookingStatusInput) {
|
|
const response = await http.patch<AdminBooking>(
|
|
`/api/admin-bookings/${bookingId}/status`,
|
|
payload
|
|
);
|
|
return response.data;
|
|
}
|