diff options
Diffstat (limited to 'src/features/reservations/domain/validateReservation.ts')
| -rw-r--r-- | src/features/reservations/domain/validateReservation.ts | 47 |
1 files changed, 47 insertions, 0 deletions
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; +} |