From 47538e50cbad770ddeb998904253afcdd51e20f6 Mon Sep 17 00:00:00 2001 From: Alberto Duarte Delgado Date: Wed, 1 Apr 2026 17:29:30 +0100 Subject: disponibilidad de reservas, home mejorado y check-in --- .../reservations/services/reservationsService.ts | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/features/reservations/services/reservationsService.ts') diff --git a/src/features/reservations/services/reservationsService.ts b/src/features/reservations/services/reservationsService.ts index 4ddf436..cc53782 100644 --- a/src/features/reservations/services/reservationsService.ts +++ b/src/features/reservations/services/reservationsService.ts @@ -35,6 +35,7 @@ function mapReservation(id: string, data: any): Reservation { startTime: data.startTime ?? '', endTime: data.endTime ?? '', status: mapReservationStatus(data.status), + checkInAt: data.checkInAt, createdAt: data.createdAt, }; } @@ -151,6 +152,32 @@ export const reservationsService = { }); }, + async checkIn(reservationId: string): Promise { + const reservationRef = doc(db, 'reservations', reservationId); + + await runTransaction(db, async (transaction) => { + const reservationSnapshot = await transaction.get(reservationRef); + + if (!reservationSnapshot.exists()) { + throw new Error('La reserva no existe'); + } + + const reservation = mapReservation(reservationSnapshot.id, reservationSnapshot.data()); + + if (reservation.status !== 'active') { + throw new Error('Solo puedes hacer check-in en reservas activas'); + } + + if (reservation.checkInAt) { + return; + } + + transaction.update(reservationRef, { + checkInAt: serverTimestamp(), + }); + }); + }, + async getByUserId(userId: string): Promise { const q = query( collection(db, 'reservations'), -- cgit v1.2.3-54-g00ecf