summaryrefslogtreecommitdiffstats
path: root/src/features/reservations/services/reservationsService.ts
diff options
context:
space:
mode:
authorAlberto Duarte Delgado <alberto@albertoduarte.com>2026-04-01 17:29:30 +0100
committerAlberto Duarte Delgado <alberto@albertoduarte.com>2026-04-01 17:29:30 +0100
commit47538e50cbad770ddeb998904253afcdd51e20f6 (patch)
tree996350fba5c88744458faa7a969b3136d189bfa3 /src/features/reservations/services/reservationsService.ts
parente22992e29801e04ca4352045c5bd2f36eac1c31c (diff)
disponibilidad de reservas, home mejorado y check-in
Diffstat (limited to 'src/features/reservations/services/reservationsService.ts')
-rw-r--r--src/features/reservations/services/reservationsService.ts27
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'),