basic booking load behavior

This commit is contained in:
Roland Schneider
2025-12-19 16:23:53 +01:00
parent 72c213eaea
commit 4e77578abf
18 changed files with 335 additions and 75 deletions

View File

@@ -0,0 +1,53 @@
import { ApiProperty } from '@nestjs/swagger';
import { Booking } from '../../entity/booking.entity';
import { UserResponseDto } from './user.response.dto';
import { PaginationResponseMetaDto } from './pagination.response.meta.dto';
export class BookingResponseDto {
@ApiProperty()
id: number;
@ApiProperty()
eventId: number;
@ApiProperty()
occurrenceStartTime: Date; // ISO String for the client
@ApiProperty({ required: false })
notes?: string;
@ApiProperty()
reservedSeatsCount: number;
@ApiProperty({ nullable: true })
canceledAt?: string;
// Flattened User Info (Avoid sending the whole User object)
@ApiProperty({
nullable: true,
type: UserResponseDto, // <--- Good practice to be explicit here too
})
user?: UserResponseDto;
constructor(booking: Booking) {
this.id = Number(booking.id); // Handle BigInt conversion
this.eventId = Number(booking.eventId);
this.occurrenceStartTime = booking.occurrenceStartTime;
this.notes = booking.notes;
this.reservedSeatsCount = booking.reservedSeatsCount;
this.canceledAt = booking.canceledAt?.toISOString() || undefined;
// Safety check: Only map user if relation is loaded
if (booking.user) {
// Assuming User entity has firstName/lastName
this.user = new UserResponseDto(booking.user);
}
}
}
export class CalenderControllerGetBookingResponse {
@ApiProperty({ type: [BookingResponseDto] })
data: BookingResponseDto[] = [];
@ApiProperty()
meta: PaginationResponseMetaDto;
}