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

@@ -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;
};