add types and schemas

This commit is contained in:
ItsMalma
2025-11-08 13:51:18 +07:00
parent b347ab0250
commit e6386648be
28 changed files with 1082 additions and 101 deletions

View File

@@ -15,10 +15,6 @@ export class Airline {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 10 })
@Unique()
code!: string;
@Property({ type: "varchar", length: 200 })
@Unique()
slug!: string;
@@ -26,6 +22,10 @@ export class Airline {
@Property({ type: "varchar", length: 100 })
name!: string;
@Property({ type: "varchar", length: 10 })
@Unique()
code!: string;
@Property({ type: "varchar", length: 100 })
@Unique()
logo!: string;

View File

@@ -16,10 +16,6 @@ export class Airport {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 10 })
@Unique()
code!: string;
@Property({ type: "varchar", length: 200 })
@Unique()
slug!: string;
@@ -27,6 +23,10 @@ export class Airport {
@Property({ type: "varchar", length: 100 })
name!: string;
@Property({ type: "varchar", length: 10 })
@Unique()
code!: string;
@ManyToOne(() => City)
city!: Rel<City>;

View File

@@ -17,7 +17,7 @@ export class FlightClass {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 420 })
@Property({ type: "varchar", length: 200 })
@Unique()
slug!: string;

View File

@@ -0,0 +1,44 @@
import { Hotel } from "@/database/entities/hotel.entity";
import { PackageDetail } from "@/database/entities/package-detail.entity";
import {
Collection,
Entity,
ManyToMany,
ManyToOne,
PrimaryKey,
Property,
type Rel,
} from "@mikro-orm/core";
@Entity()
export class HotelSchedule {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@ManyToOne(() => Hotel)
hotel!: Rel<Hotel>;
@Property({ type: "time" })
checkIn!: string;
@Property({ type: "time" })
checkOut!: string;
@Property({
type: "timestamp",
onCreate: () => new Date(),
})
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
// Inverse side
@ManyToMany(() => PackageDetail, (packageDetail) => packageDetail.tourHotels)
tourPackageDetails = new Collection<PackageDetail>(this);
}

View File

@@ -1,7 +1,6 @@
import { City } from "@/database/entities/city.entity";
import { HotelFacility } from "@/database/entities/hotel-facility.entity";
import { HotelImage } from "@/database/entities/hotel-image.entity";
import { PackageDetail } from "@/database/entities/package-detail.entity";
import {
Collection,
Entity,
@@ -84,13 +83,4 @@ export class Hotel {
owner: true,
})
facilities = new Collection<HotelFacility>(this);
@ManyToMany(() => PackageDetail, (packageDetail) => packageDetail.tourHotels)
tourPackageDetails = new Collection<PackageDetail>(this);
@OneToMany(() => PackageDetail, (packageDetail) => packageDetail.makkahHotel)
makkahPackageDetails = new Collection<PackageDetail>(this);
@OneToMany(() => PackageDetail, (packageDetail) => packageDetail.madinahHotel)
madinahPackageDetails = new Collection<PackageDetail>(this);
}

View File

@@ -1,5 +1,5 @@
import { FlightClass } from "@/database/entities/flight-class.entity";
import { Hotel } from "@/database/entities/hotel.entity";
import { HotelSchedule } from "@/database/entities/hotel-schedule.entity";
import { Package } from "@/database/entities/package.entity";
import { TransportationClass } from "@/database/entities/transportation-class.entity";
import {
@@ -29,42 +29,6 @@ export class PackageDetail {
@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,
@@ -95,9 +59,47 @@ export class PackageDetail {
)
inboundFlightClasses = new Collection<FlightClass>(this);
@ManyToMany(() => Hotel, (hotel) => hotel.tourPackageDetails, {
owner: true,
fixedOrder: true,
@ManyToMany(
() => HotelSchedule,
(hotelSchedule) => hotelSchedule.tourPackageDetails,
{
owner: true,
fixedOrder: true,
},
)
tourHotels = new Collection<HotelSchedule>(this);
@ManyToOne(() => HotelSchedule)
makkahHotel!: Rel<HotelSchedule>;
@ManyToOne(() => HotelSchedule)
madinahHotel!: Rel<HotelSchedule>;
@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(),
})
tourHotels = new Collection<Hotel>(this);
createdAt!: Date;
@Property({
type: "timestamp",
onCreate: () => new Date(),
onUpdate: () => new Date(),
})
updatedAt!: Date;
}

View File

@@ -18,7 +18,7 @@ export class TransportationClass {
@PrimaryKey({ type: "varchar", length: 30 })
id!: string;
@Property({ type: "varchar", length: 400 })
@Property({ type: "varchar", length: 200 })
@Unique()
slug!: string;

View File

@@ -16,16 +16,6 @@
"length": 30,
"mappedType": "string"
},
"code": {
"name": "code",
"type": "varchar(10)",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 10,
"mappedType": "string"
},
"slug": {
"name": "slug",
"type": "varchar(200)",
@@ -46,6 +36,16 @@
"length": 100,
"mappedType": "string"
},
"code": {
"name": "code",
"type": "varchar(10)",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 10,
"mappedType": "string"
},
"logo": {
"name": "logo",
"type": "varchar(100)",
@@ -104,20 +104,20 @@
"indexes": [
{
"columnNames": [
"code"
"slug"
],
"composite": false,
"keyName": "airline_code_unique",
"keyName": "airline_slug_unique",
"constraint": true,
"primary": false,
"unique": true
},
{
"columnNames": [
"slug"
"code"
],
"composite": false,
"keyName": "airline_slug_unique",
"keyName": "airline_code_unique",
"constraint": true,
"primary": false,
"unique": true
@@ -344,16 +344,6 @@
"length": 30,
"mappedType": "string"
},
"code": {
"name": "code",
"type": "varchar(10)",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 10,
"mappedType": "string"
},
"slug": {
"name": "slug",
"type": "varchar(200)",
@@ -374,6 +364,16 @@
"length": 100,
"mappedType": "string"
},
"code": {
"name": "code",
"type": "varchar(10)",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 10,
"mappedType": "string"
},
"city_id": {
"name": "city_id",
"type": "varchar(30)",
@@ -410,20 +410,20 @@
"indexes": [
{
"columnNames": [
"code"
"slug"
],
"composite": false,
"keyName": "airport_code_unique",
"keyName": "airport_slug_unique",
"constraint": true,
"primary": false,
"unique": true
},
{
"columnNames": [
"slug"
"code"
],
"composite": false,
"keyName": "airport_slug_unique",
"keyName": "airport_code_unique",
"constraint": true,
"primary": false,
"unique": true
@@ -697,12 +697,12 @@
},
"slug": {
"name": "slug",
"type": "varchar(420)",
"type": "varchar(200)",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 420,
"length": 200,
"mappedType": "string"
},
"flight_id": {
@@ -1283,6 +1283,100 @@
},
"nativeEnums": {}
},
{
"columns": {
"id": {
"name": "id",
"type": "varchar(30)",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 30,
"mappedType": "string"
},
"hotel_id": {
"name": "hotel_id",
"type": "varchar(30)",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 30,
"mappedType": "string"
},
"check_in": {
"name": "check_in",
"type": "time(0)",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 0,
"mappedType": "time"
},
"check_out": {
"name": "check_out",
"type": "time(0)",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 0,
"mappedType": "time"
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 6,
"mappedType": "datetime"
},
"updated_at": {
"name": "updated_at",
"type": "timestamptz",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 6,
"mappedType": "datetime"
}
},
"name": "hotel_schedule",
"schema": "public",
"indexes": [
{
"keyName": "hotel_schedule_pkey",
"columnNames": [
"id"
],
"composite": false,
"constraint": true,
"primary": true,
"unique": true
}
],
"checks": [],
"foreignKeys": {
"hotel_schedule_hotel_id_foreign": {
"constraintName": "hotel_schedule_hotel_id_foreign",
"columnNames": [
"hotel_id"
],
"localTableName": "public.hotel_schedule",
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.hotel",
"updateRule": "cascade"
}
},
"nativeEnums": {}
},
{
"columns": {
"id": {
@@ -1525,12 +1619,12 @@
},
"slug": {
"name": "slug",
"type": "varchar(400)",
"type": "varchar(200)",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"length": 400,
"length": 200,
"mappedType": "string"
},
"transportation_id": {
@@ -1830,7 +1924,7 @@
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.hotel",
"referencedTableName": "public.hotel_schedule",
"updateRule": "cascade"
},
"package_detail_madinah_hotel_id_foreign": {
@@ -1842,7 +1936,7 @@
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.hotel",
"referencedTableName": "public.hotel_schedule",
"updateRule": "cascade"
},
"package_detail_transportation_id_foreign": {
@@ -1881,8 +1975,8 @@
"length": 30,
"mappedType": "string"
},
"hotel_id": {
"name": "hotel_id",
"hotel_schedule_id": {
"name": "hotel_schedule_id",
"type": "varchar(30)",
"unsigned": false,
"autoincrement": false,
@@ -1921,16 +2015,16 @@
"deleteRule": "cascade",
"updateRule": "cascade"
},
"package_detail_tour_hotels_hotel_id_foreign": {
"constraintName": "package_detail_tour_hotels_hotel_id_foreign",
"package_detail_tour_hotels_hotel_schedule_id_foreign": {
"constraintName": "package_detail_tour_hotels_hotel_schedule_id_foreign",
"columnNames": [
"hotel_id"
"hotel_schedule_id"
],
"localTableName": "public.package_detail_tour_hotels",
"referencedColumnNames": [
"id"
],
"referencedTableName": "public.hotel",
"referencedTableName": "public.hotel_schedule",
"deleteRule": "cascade",
"updateRule": "cascade"
}

View File

@@ -0,0 +1,91 @@
import { Migration } from "@mikro-orm/migrations";
export class Migration20251108053920 extends Migration {
override async up(): Promise<void> {
this.addSql(
`create table "hotel_schedule" ("id" varchar(30) not null, "hotel_id" varchar(30) not null, "check_in" time(0) not null, "check_out" time(0) not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "hotel_schedule_pkey" primary key ("id"));`,
);
this.addSql(
`alter table "hotel_schedule" add constraint "hotel_schedule_hotel_id_foreign" foreign key ("hotel_id") references "hotel" ("id") on update cascade;`,
);
this.addSql(
`alter table "package_detail" drop constraint "package_detail_makkah_hotel_id_foreign";`,
);
this.addSql(
`alter table "package_detail" drop constraint "package_detail_madinah_hotel_id_foreign";`,
);
this.addSql(
`alter table "package_detail_tour_hotels" drop constraint "package_detail_tour_hotels_hotel_id_foreign";`,
);
this.addSql(
`alter table "flight_class" alter column "slug" type varchar(200) using ("slug"::varchar(200));`,
);
this.addSql(
`alter table "transportation_class" alter column "slug" type varchar(200) using ("slug"::varchar(200));`,
);
this.addSql(
`alter table "package_detail" add constraint "package_detail_makkah_hotel_id_foreign" foreign key ("makkah_hotel_id") references "hotel_schedule" ("id") on update cascade;`,
);
this.addSql(
`alter table "package_detail" add constraint "package_detail_madinah_hotel_id_foreign" foreign key ("madinah_hotel_id") references "hotel_schedule" ("id") on update cascade;`,
);
this.addSql(
`alter table "package_detail_tour_hotels" rename column "hotel_id" to "hotel_schedule_id";`,
);
this.addSql(
`alter table "package_detail_tour_hotels" add constraint "package_detail_tour_hotels_hotel_schedule_id_foreign" foreign key ("hotel_schedule_id") references "hotel_schedule" ("id") on update cascade on delete cascade;`,
);
}
override async down(): Promise<void> {
this.addSql(
`alter table "package_detail" drop constraint "package_detail_makkah_hotel_id_foreign";`,
);
this.addSql(
`alter table "package_detail" drop constraint "package_detail_madinah_hotel_id_foreign";`,
);
this.addSql(
`alter table "package_detail_tour_hotels" drop constraint "package_detail_tour_hotels_hotel_schedule_id_foreign";`,
);
this.addSql(`drop table if exists "hotel_schedule" cascade;`);
this.addSql(
`alter table "package_detail" drop constraint "package_detail_makkah_hotel_id_foreign";`,
);
this.addSql(
`alter table "package_detail" drop constraint "package_detail_madinah_hotel_id_foreign";`,
);
this.addSql(
`alter table "flight_class" alter column "slug" type varchar(420) using ("slug"::varchar(420));`,
);
this.addSql(
`alter table "transportation_class" alter column "slug" type varchar(400) using ("slug"::varchar(400));`,
);
this.addSql(
`alter table "package_detail" add constraint "package_detail_makkah_hotel_id_foreign" foreign key ("makkah_hotel_id") references "hotel" ("id") on update cascade;`,
);
this.addSql(
`alter table "package_detail" add constraint "package_detail_madinah_hotel_id_foreign" foreign key ("madinah_hotel_id") references "hotel" ("id") on update cascade;`,
);
this.addSql(
`alter table "package_detail_tour_hotels" rename column "hotel_schedule_id" to "hotel_id";`,
);
this.addSql(
`alter table "package_detail_tour_hotels" add constraint "package_detail_tour_hotels_hotel_id_foreign" foreign key ("hotel_id") references "hotel" ("id") on update cascade on delete cascade;`,
);
}
}