import { FlightClass } from "@/database/entities/flight-class.entity"; import { Hotel } from "@/database/entities/hotel.entity"; import { Package } from "@/database/entities/package.entity"; import { TransportationClass } from "@/database/entities/transportation-class.entity"; import { Collection, Entity, ManyToMany, ManyToOne, PrimaryKey, Property, Unique, type Rel, } from "@mikro-orm/core"; @Entity() @Unique({ properties: ["package", "departureDate"] }) export class PackageDetail { @PrimaryKey({ type: "varchar", length: 30 }) id!: string; @Property({ type: "varchar", length: 200 }) @Unique() slug!: string; @ManyToOne(() => Package) package!: Rel; @Property({ type: "date" }) departureDate!: Date; @ManyToOne(() => Hotel) makkahHotel!: Rel; @ManyToOne(() => Hotel) madinahHotel!: Rel; @ManyToOne(() => TransportationClass) transportation!: Rel; @Property({ type: "decimal", unsigned: true }) quadPrice!: number; @Property({ type: "decimal", unsigned: true }) triplePrice!: number; @Property({ type: "decimal", unsigned: true }) doublePrice!: number; @Property({ type: "decimal", nullable: true, unsigned: true }) infantPrice?: number; @Property({ type: "timestamp", onCreate: () => new Date(), }) createdAt!: Date; @Property({ type: "timestamp", onCreate: () => new Date(), onUpdate: () => new Date(), }) updatedAt!: Date; // Collections @ManyToMany( () => FlightClass, (flightClass) => flightClass.tourPackageDetails, { owner: true, fixedOrder: true, }, ) tourFlightClasses = new Collection(this); @ManyToMany( () => FlightClass, (flightClass) => flightClass.outboundPackageDetails, { owner: true, fixedOrder: true, }, ) outboundFlightClasses = new Collection(this); @ManyToMany( () => FlightClass, (flightClass) => flightClass.inboundPackageDetails, { owner: true, fixedOrder: true, }, ) inboundFlightClasses = new Collection(this); @ManyToMany(() => Hotel, (hotel) => hotel.tourPackageDetails, { owner: true, fixedOrder: true, }) tourHotels = new Collection(this); }