From 174f1acd46c4ffbde88c04465e8fa6b6810ce113 Mon Sep 17 00:00:00 2001 From: Alberto Duarte Delgado Date: Mon, 30 Mar 2026 17:37:42 +0100 Subject: logica de reservas --- .../reservations/domain/validateReservation.ts | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/features/reservations/domain/validateReservation.ts (limited to 'src/features/reservations/domain/validateReservation.ts') diff --git a/src/features/reservations/domain/validateReservation.ts b/src/features/reservations/domain/validateReservation.ts new file mode 100644 index 0000000..40055c0 --- /dev/null +++ b/src/features/reservations/domain/validateReservation.ts @@ -0,0 +1,47 @@ +import { CreateReservationInput } from '@/features/reservations/types'; + +export function validateReservation(input: CreateReservationInput): string | null { + if (!input.officeId.trim()) { + return 'No se indicó una oficina válida'; + } + + if (!input.officeName.trim()) { + return 'No se indicó el nombre de la oficina'; + } + + if (!input.userId.trim()) { + return 'No se identificó al usuario'; + } + + if (!input.userEmail.trim()) { + return 'No se identificó el correo del usuario'; + } + + if (!input.date.trim()) { + return 'La fecha es obligatoria'; + } + + if (!input.startTime.trim()) { + return 'La hora de inicio es obligatoria'; + } + + if (!input.endTime.trim()) { + return 'La hora de fin es obligatoria'; + } + + const datePattern = /^\d{4}-\d{2}-\d{2}$/; + if (!datePattern.test(input.date)) { + return 'La fecha debe tener formato YYYY-MM-DD'; + } + + const timePattern = /^\d{2}:\d{2}$/; + if (!timePattern.test(input.startTime) || !timePattern.test(input.endTime)) { + return 'Las horas deben tener formato HH:MM'; + } + + if (input.endTime <= input.startTime) { + return 'La hora de fin debe ser posterior a la de inicio'; + } + + return null; +} -- cgit v1.2.3-54-g00ecf