- Implemented email confirmation for admin and public bookings. - Added customerEmail field to booking schemas and services. - Created email templates for booking confirmation, cancellation, and no-show notifications. - Updated booking handlers to send emails upon booking creation and status updates. - Enhanced frontend forms to capture customer email during booking creation.
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import {
|
|
AdminBookingServiceError,
|
|
createAdminBooking,
|
|
} from '@/modules/admin-booking/services/admin-booking.service';
|
|
import { sendBookingConfirmation } from '@/services/booking-email.service';
|
|
import type { AppContext } from '@/types/hono';
|
|
import type { CreateAdminBookingInput } from '@repo/api-contract';
|
|
|
|
type ComplexIdParams = { complexId: string };
|
|
|
|
export async function createAdminBookingHandler(c: AppContext) {
|
|
const { complexId } = c.req.valid('param' as never) as ComplexIdParams;
|
|
const payload = c.req.valid('json' as never) as CreateAdminBookingInput;
|
|
const user = c.get('user');
|
|
|
|
try {
|
|
const booking = await createAdminBooking(user.id, complexId, payload);
|
|
|
|
void sendBookingConfirmation({
|
|
bookingCode: booking.bookingCode,
|
|
complexName: booking.complexName,
|
|
date: booking.date,
|
|
startTime: booking.startTime,
|
|
endTime: booking.endTime,
|
|
courtName: booking.courtName,
|
|
sportName: booking.sport.name,
|
|
customerName: booking.customerName,
|
|
customerEmail: booking.customerEmail,
|
|
price: booking.price,
|
|
});
|
|
|
|
return c.json(booking, 201);
|
|
} catch (error) {
|
|
if (error instanceof AdminBookingServiceError) {
|
|
return c.json({ message: error.message }, error.status);
|
|
}
|
|
throw error;
|
|
}
|
|
}
|