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) // Cancel a specific booking (soft delete)
@ApiCreatedResponse({ type: CalenderControllerGetBookingResponse })
@Patch('bookings/:bookingId/cancel') @Patch('bookings/:bookingId/cancel')
cancelBooking( cancelBooking(
@User() user: types.AppUser,
@Param('bookingId', ParseIntPipe) bookingId: number, @Param('bookingId', ParseIntPipe) bookingId: number,
@Body() cancelBookingDto: CancelBookingDto, @Body() cancelBookingDto: CancelBookingDto,
) { ) {
return this.calendarService.cancelBooking(bookingId, cancelBookingDto); return this.calendarService.cancelBooking(bookingId, user.user!.userId, {
canceledReason: cancelBookingDto.canceledReason,
});
} }
@Get('bookings/:eventId') @Get('bookings/:eventId')

View File

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

View File

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