feat(booking): add validation to prevent past bookings and implement slot validation logic

This commit is contained in:
Jose Selesan
2026-06-08 15:46:17 -03:00
parent 49d2a13672
commit 630dedb507
4 changed files with 134 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
import { randomInt } from 'node:crypto';
import { CourtBookingStatus } from '@/generated/prisma/enums';
import { db } from '@/lib/prisma';
import { isSlotInPast } from '@/lib/slot-validator';
import { evaluatePlanUsage, parsePlanRules } from '@/modules/plan/services/plan-rules.service';
import type { DayOfWeek } from '@repo/api-contract';
import type {
@@ -361,6 +362,10 @@ export async function createAdminBooking(
);
}
if (isSlotInPast(bookingDate, input.startTime, court.slotDurationMinutes)) {
throw new AdminBookingServiceError('No se pueden crear reservas en el pasado.', 400);
}
for (let attempt = 0; attempt < 5; attempt += 1) {
try {
const booking = await db.$transaction(async (tx) => {