setup database, entities, and migrations

This commit is contained in:
ItsMalma
2025-11-04 18:02:28 +07:00
parent 9aa0de17ee
commit b347ab0250
25 changed files with 3608 additions and 1 deletions

View 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);
}