- 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.
53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
import {
|
|
AdminBookingServiceError,
|
|
updateAdminBookingStatus,
|
|
} from '@/modules/admin-booking/services/admin-booking.service';
|
|
import { sendBookingCancelled, sendBookingNoShow } from '@/services/booking-email.service';
|
|
import type { AppContext } from '@/types/hono';
|
|
import type { UpdateAdminBookingStatusInput } from '@repo/api-contract';
|
|
|
|
type BookingIdParams = { id: string };
|
|
|
|
export async function updateAdminBookingStatusHandler(c: AppContext) {
|
|
const { id } = c.req.valid('param' as never) as BookingIdParams;
|
|
const payload = c.req.valid('json' as never) as UpdateAdminBookingStatusInput;
|
|
const user = c.get('user');
|
|
|
|
try {
|
|
const booking = await updateAdminBookingStatus(user.id, id, payload);
|
|
|
|
if (payload.status === 'CANCELLED') {
|
|
void sendBookingCancelled({
|
|
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,
|
|
});
|
|
} else if (payload.status === 'NOSHOW') {
|
|
void sendBookingNoShow({
|
|
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,
|
|
});
|
|
}
|
|
|
|
return c.json(booking);
|
|
} catch (error) {
|
|
if (error instanceof AdminBookingServiceError) {
|
|
return c.json({ message: error.message }, error.status);
|
|
}
|
|
throw error;
|
|
}
|
|
}
|