cancel booking
This commit is contained in:
@@ -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')
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user