cancel booking

This commit is contained in:
Roland Schneider
2025-12-20 21:55:22 +01:00
parent e9943dae76
commit 90c192c881
3 changed files with 12 additions and 7 deletions

View File

@@ -94,12 +94,16 @@ export class CalendarController {
}
// Cancel a specific booking (soft delete)
@ApiCreatedResponse({ type: CalenderControllerGetBookingResponse })
@Patch('bookings/:bookingId/cancel')
cancelBooking(
@User() user: types.AppUser,
@Param('bookingId', ParseIntPipe) bookingId: number,
@Body() cancelBookingDto: CancelBookingDto,
) {
return this.calendarService.cancelBooking(bookingId, cancelBookingDto);
return this.calendarService.cancelBooking(bookingId, user.user!.userId, {
canceledReason: cancelBookingDto.canceledReason,
});
}
@Get('bookings/:eventId')

View File

@@ -584,9 +584,12 @@ export class CalendarService {
async cancelBooking(
bookingId: number,
userId: number,
cancelBookingDto: CancelBookingDto,
): Promise<Booking> {
const booking = await this.bookingRepository.findOneBy({ id: bookingId });
const booking = await this.bookingRepository.findOne({
where: { id: bookingId },
});
if (!booking) {
throw new NotFoundException(`Booking with ID ${bookingId} not found.`);
}
@@ -597,7 +600,7 @@ export class CalendarService {
// Update the booking with cancellation details
booking.canceledAt = new Date();
booking.canceledReason = cancelBookingDto.canceledReason || null;
booking.canceledByUserId = cancelBookingDto.canceledByUserId;
booking.canceledByUserId = userId;
return this.bookingRepository.save(booking);
}

View File

@@ -7,9 +7,7 @@ import {
} from 'class-validator';
export class CancelBookingDto {
@IsNotEmpty()
@IsInt()
canceledByUserId: number;
@IsOptional()
@IsString()