basic booking load behavior
This commit is contained in:
53
server/src/calendar/dto/booking.response.dto.ts
Normal file
53
server/src/calendar/dto/booking.response.dto.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user