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

34
src/common/schemas.ts Normal file
View File

@@ -0,0 +1,34 @@
import { isValid, parse } from "date-fns";
import z from "zod";
export const timeSchema = z
.string("Must be string.")
.nonempty("Must not be empty.")
.transform((val, ctx) => {
const parsedDate = parse(val, "HH:mm", new Date());
if (!isValid(parsedDate)) {
ctx.issues.push({
code: "custom",
message: "Must be in 'HH:mm' format.",
input: val,
});
return z.NEVER;
}
return val;
});
export const dateSchema = z
.string("Must be string.")
.nonempty("Must not be empty.")
.transform((val, ctx) => {
const parsedDate = parse(val, "YYYY-MM-DD", new Date());
if (!isValid(parsedDate)) {
ctx.issues.push({
code: "custom",
message: "Must be in 'YYYY-MM-DD' format.",
input: val,
});
return z.NEVER;
}
return val;
});

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;`,
);
}
}

View File

@@ -0,0 +1,29 @@
import z from "zod";
export const airlineRequestSchema = z.object({
name: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
code: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(10, "Max 10 characters."),
logo: z.base64("Must be base64 string.").nonempty("Must not empty."),
skytrax_rating: z
.number("Must be number.")
.int("Must be integer.")
.min(1, "Minimum 1.")
.max(5, "Maximum 5."),
skytrax_type: z.enum(
["full_service", "low_cost"],
"Must be either 'full_service' or 'low_cost'.",
),
});
export const airlineQuerySchema = z.object({
slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
});

View File

@@ -0,0 +1,21 @@
import type {
airlineQuerySchema,
airlineRequestSchema,
} from "@/modules/airline/airline.schemas";
import z from "zod";
export type AirlineRequest = z.infer<typeof airlineRequestSchema>;
export type AirlineQuery = z.infer<typeof airlineQuerySchema>;
export type AirlineResponse = {
id: string;
slug: string;
name: string;
code: string;
logo: string;
skytrax_rating: number;
skytrax_type: "full_service" | "low_cost";
created_at: Date;
updated_at: Date;
};

View File

@@ -0,0 +1,23 @@
import z from "zod";
export const airportRequestSchema = z.object({
name: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
code: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(10, "Max 10 characters."),
city_slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
});
export const airportQuerySchema = z.object({
slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
});

View File

@@ -0,0 +1,20 @@
import type {
airportQuerySchema,
airportRequestSchema,
} from "@/modules/airport/airport.schemas";
import type { CityResponse } from "@/modules/city/city.types";
import z from "zod";
export type AirportRequest = z.infer<typeof airportRequestSchema>;
export type AirportQuery = z.infer<typeof airportQuerySchema>;
export type AirportResponse = {
id: string;
slug: string;
name: string;
code: string;
city: CityResponse;
created_at: Date;
updated_at: Date;
};

View File

@@ -0,0 +1,19 @@
import z from "zod";
export const cityRequestSchema = z.object({
name: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
country_slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
});
export const cityQuerySchema = z.object({
slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
});

View File

@@ -0,0 +1,19 @@
import type {
cityQuerySchema,
cityRequestSchema,
} from "@/modules/city/city.schemas";
import type { CountryResponse } from "@/modules/country/country.types";
import z from "zod";
export type CityRequest = z.infer<typeof cityRequestSchema>;
export type CityQuery = z.infer<typeof cityQuerySchema>;
export type CityResponse = {
id: string;
slug: string;
name: string;
country: CountryResponse;
created_at: Date;
updated_at: Date;
};

View File

@@ -0,0 +1,15 @@
import z from "zod";
export const countryRequestSchema = z.object({
name: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
});
export const countryQuerySchema = z.object({
slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
});

View File

@@ -0,0 +1,17 @@
import type {
countryQuerySchema,
countryRequestSchema,
} from "@/modules/country/country.schemas";
import z from "zod";
export type CountryRequest = z.infer<typeof countryRequestSchema>;
export type CountryQuery = z.infer<typeof countryQuerySchema>;
export type CountryResponse = {
id: string;
slug: string;
name: string;
created_at: Date;
updated_at: Date;
};

View File

@@ -0,0 +1,83 @@
import { timeSchema } from "@/common/schemas";
import z from "zod";
export const flightRequestSchema = z.object({
airline_slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
number: z
.number("Must be number.")
.int("Must be integer.")
.positive("Must be positive."),
departure_airport_slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
departure_terminal: z
.string("Must be string.")
.max(100, "Max 100 characters.")
.nullable(),
departure_gate: z
.string("Must be string.")
.max(100, "Max 100 characters.")
.nullable(),
departure_time: timeSchema,
arrival_airport_slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
arrival_terminal: z
.string("Must be string.")
.max(100, "Max 100 characters.")
.nullable(),
arrival_gate: z
.string("Must be string.")
.max(100, "Max 100 characters.")
.nullable(),
duration: z
.number("Must be number.")
.int("Must be integer.")
.positive("Must be positive."),
aircraft: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
});
export const flightClassRequestSchema = z.object({
class: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
seat_layout: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(10, "Max 10 characters."),
baggage: z
.number("Must be number.")
.int("Must be integer.")
.positive("Must be positive."),
cabin_baggage: z
.number("Must be number.")
.int("Must be integer.")
.positive("Must be positive."),
});
export const flightQuerySchema = z.object({
slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(220, "Max 220 characters."),
});
export const flightClassQuerySchema = z.object({
flight_slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(220, "Max 220 characters."),
slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(420, "Max 420 characters."),
});

View File

@@ -0,0 +1,48 @@
import type { AirlineResponse } from "@/modules/airline/airline.types";
import type { AirportResponse } from "@/modules/airport/airport.types";
import type {
flightClassQuerySchema,
flightClassRequestSchema,
flightQuerySchema,
flightRequestSchema,
} from "@/modules/flight/flight.schemas";
import z from "zod";
export type FlightRequest = z.infer<typeof flightRequestSchema>;
export type FlightClassRequest = z.infer<typeof flightClassRequestSchema>;
export type FlightQuery = z.infer<typeof flightQuerySchema>;
export type FlightClassQuery = z.infer<typeof flightClassQuerySchema>;
export type FlightResponse = {
id: string;
slug: string;
airline: AirlineResponse;
number: number;
departure_airport: AirportResponse;
departure_terminal: string | null;
departure_gate: string | null;
departure_time: string;
arrival_airport: AirportResponse;
arrival_terminal: string | null;
arrival_gate: string | null;
arrival_time: string;
duration: number;
aircraft: string;
created_at: Date;
updated_at: Date;
};
export type FlightClassResponse = {
id: string;
slug: string;
flight: FlightResponse;
class: string;
seat_layout: string;
baggage: number;
cabin_baggage: number;
created_at: Date;
updated_at: Date;
};

View File

@@ -0,0 +1,96 @@
import z from "zod";
export const hotelFacilityRequestSchema = z.object({
name: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
icon: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
});
export const hotelRequestSchema = z.object({
name: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
city_slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
star: z
.number("Must be number.")
.int("Must be integer.")
.min(1, "Minimum 1.")
.max(7, "Maximum 7."),
images: z
.array(
z.base64("Must be base64 string.").nonempty("Must not empty."),
"Must be array.",
)
.nonempty("Must not empty."),
google_maps_link: z
.url("Must be valid string URL.")
.nonempty("Must not empty.")
.max(500, "Max 500 characters."),
google_maps_embed: z
.url("Must be valid string URL.")
.nonempty("Must not empty.")
.max(500, "Max 500 characters."),
google_reviews_link: z
.url("Must be valid string URL.")
.nonempty("Must not empty.")
.max(500, "Max 500 characters."),
description: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(1000, "Max 1000 characters."),
facility_slugs: z
.array(
z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
"Must be array.",
)
.nonempty("Must not empty."),
address: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
landmark: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
distance_to_landmark: z
.number("Must be number.")
.positive("Must be positive."),
food_type: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
food_amount: z
.number("Must be number.")
.int("Must be integer.")
.positive("Must be positive."),
food_menu: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
});
export const hotelFacilityQuerySchema = z.object({
slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
});
export const hotelQuerySchema = z.object({
slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
});

View File

@@ -0,0 +1,45 @@
import type { CityResponse } from "@/modules/city/city.types";
import type {
hotelFacilityRequestSchema,
hotelQuerySchema,
hotelRequestSchema,
} from "@/modules/hotel/hotel.schemas";
import z from "zod";
export type HotelFacilityRequest = z.infer<typeof hotelFacilityRequestSchema>;
export type HotelRequest = z.infer<typeof hotelRequestSchema>;
export type HotelFacilityQuery = z.infer<typeof hotelFacilityRequestSchema>;
export type HotelQuery = z.infer<typeof hotelQuerySchema>;
export type HotelFacilityResponse = {
id: string;
slug: string;
name: string;
icon: string;
created_at: Date;
updated_at: Date;
};
export type HotelResponse = {
id: string;
slug: string;
name: string;
city: CityResponse;
star: number;
google_maps_link: string;
google_maps_embed: string;
google_reviews_link: string;
description: string;
facilities: HotelFacilityResponse[];
address: string;
landmark: string;
distance_to_landmark: number;
food_type: string;
food_amount: number;
food_menu: string;
created_at: Date;
updated_at: Date;
};

View File

@@ -0,0 +1,122 @@
import { dateSchema, timeSchema } from "@/common/schemas";
import z from "zod";
export const packageRequestSchema = z.object({
name: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
type: z.enum(["reguler", "plus"], "Must be either 'reguler' or 'plus'."),
class: z.enum(
["silver", "gold", "platinum"],
"Must be either 'silver', 'gold', or 'platinum'.",
),
thumbnail: z.base64("Must be base64 string.").nonempty("Must not empty."),
use_fast_train: z.boolean("Must be boolean."),
});
export const packageDetailRequestSchema = z.object({
departure_date: dateSchema,
tour_flight_slugs: z
.array(
z
.string("Must be string.")
.nonempty("Must not empty.")
.max(420, "Max 420 characters."),
"Must be array.",
)
.nonempty("Must not empty."),
outbound_flight_slugs: z
.array(
z
.string("Must be string.")
.nonempty("Must not empty.")
.max(420, "Max 420 characters."),
"Must be array.",
)
.nonempty("Must not empty."),
inbound_flight_slugs: z
.array(
z
.string("Must be string.")
.nonempty("Must not empty.")
.max(420, "Max 420 characters."),
"Must be array.",
)
.nonempty("Must not empty."),
tour_hotels: z.array(
z.object(
{
hotel_slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
check_in: timeSchema,
check_out: timeSchema,
},
"Must be object.",
),
"Must be array.",
),
makkah_hotel: z.object(
{
hotel_slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
check_in: timeSchema,
check_out: timeSchema,
},
"Must be object.",
),
madinah_hotel: z.object(
{
hotel_slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
check_in: timeSchema,
check_out: timeSchema,
},
"Must be object.",
),
transportation_slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
quad_price: z
.number("Must be number.")
.int("Must be integer.")
.positive("Must be positive."),
triple_price: z
.number("Must be number.")
.int("Must be integer.")
.positive("Must be positive."),
double_price: z
.number("Must be number.")
.int("Must be integer.")
.positive("Must be positive."),
infant_price: z
.number("Must be number.")
.int("Must be integer.")
.positive("Must be positive.")
.nullable(),
});
export const packageQuerySchema = z.object({
detail_slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
});
export const packageDetailQuerySchema = z.object({
slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
});

View File

@@ -0,0 +1,56 @@
import type { FlightClassResponse } from "@/modules/flight/flight.types";
import type { HotelResponse } from "@/modules/hotel/hotel.types";
import type {
packageDetailQuerySchema,
packageDetailRequestSchema,
packageQuerySchema,
packageRequestSchema,
} from "@/modules/package/package.schemas";
import type { TransportationClassResponse } from "@/modules/transportation/transportation.types";
import z from "zod";
export type PackageRequest = z.infer<typeof packageRequestSchema>;
export type PackageDetailRequest = z.infer<typeof packageDetailRequestSchema>;
export type PackageQuery = z.infer<typeof packageQuerySchema>;
export type PackageDetailQuery = z.infer<typeof packageDetailQuerySchema>;
export type PackageResponse = {
id: string;
slug: string;
name: string;
type: "reguler" | "plus";
class: "silver" | "gold" | "platinum";
thumbnail: string;
use_fast_train: boolean;
created_at: Date;
updated_at: Date;
};
export type PackageHotelResponse = {
hotel: HotelResponse;
check_in: string;
check_out: string;
};
export type PackageDetailResponse = {
id: string;
slug: string;
package: PackageResponse;
departure_date: string;
tour_flights: FlightClassResponse[];
outbound_flights: FlightClassResponse[];
inbound_flights: FlightClassResponse[];
tour_hotels: PackageHotelResponse[];
makkah_hotel: PackageHotelResponse;
medina_hotel: PackageHotelResponse;
transportation: TransportationClassResponse;
quad_price: number;
triple_price: number;
double_price: number;
infant_price: number | null;
created_at: Date;
updated_at: Date;
};

View File

@@ -0,0 +1,47 @@
import z from "zod";
export const transportationRequestSchema = z.object({
name: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
type: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
});
export const transportationClassRequestSchema = z.object({
class: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(100, "Max 100 characters."),
total_seats: z
.number("Must be number.")
.int("Must be integer.")
.positive("Must be positive."),
images: z
.array(
z.base64("Must be base64 string.").nonempty("Must not empty."),
"Must be array.",
)
.nonempty("Must not empty."),
});
export const transportationQuerySchema = z.object({
slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
});
export const transportationClassQuerySchema = z.object({
transportation_slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(200, "Max 200 characters."),
slug: z
.string("Must be string.")
.nonempty("Must not empty.")
.max(400, "Max 400 characters."),
});

View File

@@ -0,0 +1,38 @@
import type {
transportationClassQuerySchema,
transportationClassRequestSchema,
transportationQuerySchema,
transportationRequestSchema,
} from "@/modules/transportation/transportation.schemas";
import z from "zod";
export type TransportationRequest = z.infer<typeof transportationRequestSchema>;
export type TransportationClassRequest = z.infer<
typeof transportationClassRequestSchema
>;
export type TransportationQuery = z.infer<typeof transportationQuerySchema>;
export type TransportationClassQuery = z.infer<
typeof transportationClassQuerySchema
>;
export type TransportationResponse = {
id: string;
slug: string;
name: string;
created_at: Date;
updated_at: Date;
};
export type TransportationClassResponse = {
id: string;
slug: string;
transportation: TransportationResponse;
class: string;
total_seats: number;
images: string[];
created_at: Date;
updated_at: Date;
};