feat: implement real-time booking updates using Server-Sent Events (SSE) and add public booking URL sharing to the dashboard
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { sseManager } from '@/lib/sse';
|
||||
import {
|
||||
PublicBookingServiceError,
|
||||
createPublicBooking,
|
||||
@@ -13,6 +14,22 @@ export async function createPublicBookingHandler(c: AppContext) {
|
||||
|
||||
try {
|
||||
const booking = await createPublicBooking(complexSlug, payload);
|
||||
|
||||
const channel = `complex-${booking.complexId}`;
|
||||
sseManager.emit(
|
||||
channel,
|
||||
JSON.stringify({
|
||||
type: 'booking_created',
|
||||
booking: {
|
||||
id: booking.id,
|
||||
courtId: booking.courtId,
|
||||
date: booking.date,
|
||||
startTime: booking.startTime,
|
||||
endTime: booking.endTime,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
return c.json(booking, 201);
|
||||
} catch (error) {
|
||||
if (error instanceof PublicBookingServiceError) {
|
||||
|
||||
@@ -183,6 +183,7 @@ async function getComplexWithBookingData(complexSlug: string) {
|
||||
id: true,
|
||||
complexName: true,
|
||||
complexSlug: true,
|
||||
physicalAddress: true,
|
||||
plan: {
|
||||
select: {
|
||||
rules: true,
|
||||
@@ -414,6 +415,7 @@ export async function listPublicAvailability(complexSlug: string, query: PublicA
|
||||
return {
|
||||
complexId: complex.id,
|
||||
complexName: complex.complexName,
|
||||
complexAddress: complex.physicalAddress ?? null,
|
||||
complexSlug: complex.complexSlug,
|
||||
date: query.date,
|
||||
sportSelectionRequired,
|
||||
|
||||
Reference in New Issue
Block a user