A robust RESTful API for managing bookings and reservations built with TypeScript, Express, and MongoDB.
A comprehensive backend solution for managing bookings and reservations with a focus on security, scalability, and developer experience.
This API implements a clean, modular architecture with:
The codebase follows best practices including:
// Example booking controller with validation
export const createBooking = async (req: Request, res: Response) => {
try {
const { userId, resourceId, startTime, endTime } = req.body;
// Check for availability
const isAvailable = await checkAvailability(resourceId, startTime, endTime);
if (!isAvailable) {
return res.status(409).json({
success: false,
message: "Resource not available for requested time slot"
});
}
// Create booking
const newBooking = await Booking.create({
userId,
resourceId,
startTime: new Date(startTime),
endTime: new Date(endTime),
status: "confirmed"
});
return res.status(201).json({
success: true,
data: newBooking
});
} catch (error) {
return res.status(500).json({
success: false,
message: "Failed to create booking",
error: error.message
});
}
};