diff options
Diffstat (limited to 'src/features/reservations/services')
| -rw-r--r-- | src/features/reservations/services/reservationsService.ts | 27 |
1 files changed, 27 insertions, 0 deletions
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<void> { + 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<Reservation[]> { const q = query( collection(db, 'reservations'), |