add types and schemas
This commit is contained in:
122
src/modules/package/package.schemas.ts
Normal file
122
src/modules/package/package.schemas.ts
Normal 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."),
|
||||
});
|
||||
56
src/modules/package/package.types.ts
Normal file
56
src/modules/package/package.types.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user