69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
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;
|
|
|
|
@ApiProperty({ nullable: true })
|
|
createdAt?: string; // ISO String for the client
|
|
|
|
// Flattened User Info (Avoid sending the whole User object)
|
|
@ApiProperty({
|
|
nullable: true,
|
|
type: UserResponseDto, // <--- Good practice to be explicit here too
|
|
})
|
|
user?: UserResponseDto;
|
|
|
|
@ApiProperty({ required: false })
|
|
status?: string;
|
|
|
|
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;
|
|
this.createdAt = booking.createdAt?.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);
|
|
}
|
|
this.status = 'active';
|
|
if (booking.canceledAt) {
|
|
if (booking.canceledReason == 'customer_cancelled') {
|
|
this.status = 'customer_cancelled';
|
|
} else {
|
|
this.status = 'cancelled';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export class CalenderControllerGetBookingResponse {
|
|
@ApiProperty({ type: [BookingResponseDto] })
|
|
data: BookingResponseDto[] = [];
|
|
@ApiProperty()
|
|
meta: PaginationResponseMetaDto;
|
|
}
|