setup database, entities, and migrations
This commit is contained in:
103
src/database/entities/package-detail.entity.ts
Normal file
103
src/database/entities/package-detail.entity.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
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<Package>;
|
||||
|
||||
@Property({ type: "date" })
|
||||
departureDate!: Date;
|
||||
|
||||
@ManyToOne(() => Hotel)
|
||||
makkahHotel!: Rel<Hotel>;
|
||||
|
||||
@ManyToOne(() => Hotel)
|
||||
madinahHotel!: Rel<Hotel>;
|
||||
|
||||
@ManyToOne(() => TransportationClass)
|
||||
transportation!: Rel<TransportationClass>;
|
||||
|
||||
@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<FlightClass>(this);
|
||||
|
||||
@ManyToMany(
|
||||
() => FlightClass,
|
||||
(flightClass) => flightClass.outboundPackageDetails,
|
||||
{
|
||||
owner: true,
|
||||
fixedOrder: true,
|
||||
},
|
||||
)
|
||||
outboundFlightClasses = new Collection<FlightClass>(this);
|
||||
|
||||
@ManyToMany(
|
||||
() => FlightClass,
|
||||
(flightClass) => flightClass.inboundPackageDetails,
|
||||
{
|
||||
owner: true,
|
||||
fixedOrder: true,
|
||||
},
|
||||
)
|
||||
inboundFlightClasses = new Collection<FlightClass>(this);
|
||||
|
||||
@ManyToMany(() => Hotel, (hotel) => hotel.tourPackageDetails, {
|
||||
owner: true,
|
||||
fixedOrder: true,
|
||||
})
|
||||
tourHotels = new Collection<Hotel>(this);
|
||||
}
|
||||
Reference in New Issue
Block a user