Added booking logs to keep track of cancelled bookings and no shows

This commit is contained in:
Jose Selesan
2026-05-06 16:54:48 -03:00
parent bb48d9c164
commit 41a217e8a9
13 changed files with 232 additions and 34 deletions

View File

@@ -164,7 +164,7 @@ function mapBookingResponse(booking: {
endTime: string;
customerName: string;
customerPhone: string;
status: 'CONFIRMED' | 'CANCELLED' | 'COMPLETED';
status: 'CONFIRMED' | 'CANCELLED' | 'COMPLETED' | 'NOSHOW';
createdAt: Date;
updatedAt: Date;
court: {
@@ -494,34 +494,42 @@ export async function updateAdminBookingStatus(
);
}
const updated = await db.courtBooking.update({
where: { id: booking.id },
if(input.status === 'NOSHOW' && booking.status !== 'CONFIRMED') {
throw new AdminBookingServiceError(
'Solo se pueden marcar como no show las reservas confirmadas.',
409
);
}
await db.courtBookingLog.create({
data: {
status:
input.status === 'COMPLETED' ? CourtBookingStatus.COMPLETED : CourtBookingStatus.CANCELLED,
},
include: {
court: {
select: {
id: true,
name: true,
sport: {
select: {
id: true,
name: true,
slug: true,
},
},
complex: {
select: {
id: true,
complexName: true,
},
},
},
},
id: uuidv7(),
bookingCode: booking.bookingCode,
courtId: booking.court.id,
bookingDate: booking.bookingDate,
startTime: booking.startTime,
endTime: booking.endTime,
customerName: booking.customerName,
customerPhone: booking.customerPhone,
previousStatus: booking.status,
newStatus: input.status,
changedAt: new Date(),
},
});
return mapBookingResponse(updated);
if(input.status === 'COMPLETED' || input.status ==='NOSHOW') {
await db.courtBooking.update({
where: { id: booking.id },
data: {
status: input.status,
},
});
} else {
// if the booking is cancelled we delete it to free up the slot, but we keep a log of it with the cancelled status
await db.courtBooking.delete({
where: { id: booking.id },
})
}
return mapBookingResponse({...booking, status: input.status });
}