cancel booking
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -7,9 +7,7 @@ import {
|
||||
} from 'class-validator';
|
||||
|
||||
export class CancelBookingDto {
|
||||
@IsNotEmpty()
|
||||
@IsInt()
|
||||
canceledByUserId: number;
|
||||
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
|
||||
Reference in New Issue
Block a user