stashing code
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { z } from "zod";
|
||||
import { PackageType, PaymentMethod } from "./enums";
|
||||
export * from "../../../passengerinfo/data/entities";
|
||||
|
||||
// Flight package selection models
|
||||
|
||||
export const packageSelectionModel = z.object({
|
||||
packageType: z.enum([
|
||||
PackageType.Basic,
|
||||
PackageType.Flex,
|
||||
PackageType.Premium,
|
||||
]),
|
||||
insurance: z.boolean().default(false),
|
||||
});
|
||||
export type PackageSelection = z.infer<typeof packageSelectionModel>;
|
||||
|
||||
// payment models
|
||||
|
||||
export const cardInfoModel = z.object({
|
||||
nameOnCard: z.string().min(1).max(255),
|
||||
number: z.string().max(20),
|
||||
expiryDate: z.string().max(8),
|
||||
cvv: z.string().max(6),
|
||||
});
|
||||
export type CardInfo = z.infer<typeof cardInfoModel>;
|
||||
|
||||
export const paymentInfoModel = z.object({
|
||||
method: z.enum([PaymentMethod.Card]).default(PaymentMethod.Card),
|
||||
cardInfo: cardInfoModel,
|
||||
});
|
||||
export type PaymentInfo = z.infer<typeof paymentInfoModel>;
|
||||
43
packages/logic/domains/ticket/data/entities/enums.ts
Normal file
43
packages/logic/domains/ticket/data/entities/enums.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
export enum CheckoutStep {
|
||||
Setup = "SETUP",
|
||||
Initial = "INITIAL",
|
||||
Payment = "PAYMENT",
|
||||
Verification = "VERIFICATION",
|
||||
Confirmation = "CONFIRMATION",
|
||||
Complete = "COMPLETE",
|
||||
}
|
||||
|
||||
export const TicketType = {
|
||||
OneWay: "ONEWAY",
|
||||
Return: "RETURN",
|
||||
};
|
||||
|
||||
export const CabinClass = {
|
||||
Economy: "ECONOMY",
|
||||
PremiumEconomy: "PREMIUM_ECONOMY",
|
||||
Business: "BUSINESS",
|
||||
FirstClass: "FIRST_CLASS",
|
||||
};
|
||||
|
||||
export enum Gender {
|
||||
Male = "male",
|
||||
Female = "female",
|
||||
Other = "other",
|
||||
}
|
||||
|
||||
export enum PaymentMethod {
|
||||
Card = "CARD",
|
||||
GooglePay = "GOOGLE_PAY",
|
||||
ApplePay = "APPLEPAY",
|
||||
}
|
||||
|
||||
export enum PassengerType {
|
||||
Adult = "adult",
|
||||
Child = "child",
|
||||
}
|
||||
|
||||
export enum PackageType {
|
||||
Basic = "basic",
|
||||
Flex = "flex",
|
||||
Premium = "premium",
|
||||
}
|
||||
178
packages/logic/domains/ticket/data/entities/index.ts
Normal file
178
packages/logic/domains/ticket/data/entities/index.ts
Normal file
@@ -0,0 +1,178 @@
|
||||
import { z } from "zod";
|
||||
import { CabinClass, TicketType } from "./enums";
|
||||
|
||||
export * from "./enums";
|
||||
|
||||
export const stationModel = z.object({
|
||||
id: z.number(),
|
||||
type: z.string(),
|
||||
code: z.string(),
|
||||
name: z.string(),
|
||||
city: z.string(),
|
||||
country: z.string(),
|
||||
});
|
||||
export type Station = z.infer<typeof stationModel>;
|
||||
|
||||
export const iteneraryStationModel = z.object({
|
||||
station: stationModel,
|
||||
localTime: z.string(),
|
||||
utcTime: z.string(),
|
||||
});
|
||||
export type IteneraryStation = z.infer<typeof iteneraryStationModel>;
|
||||
|
||||
export const seatInfoModel = z.object({
|
||||
availableSeats: z.number(),
|
||||
seatClass: z.string(),
|
||||
});
|
||||
export type SeatInfo = z.infer<typeof seatInfoModel>;
|
||||
|
||||
export const flightPriceDetailsModel = z.object({
|
||||
currency: z.string(),
|
||||
basePrice: z.number(),
|
||||
discountAmount: z.number(),
|
||||
displayPrice: z.number(),
|
||||
orderPrice: z.number().nullable().optional(),
|
||||
appliedCoupon: z.string().nullish().optional(),
|
||||
couponDescription: z.string().nullish().optional(),
|
||||
});
|
||||
export type FlightPriceDetails = z.infer<typeof flightPriceDetailsModel>;
|
||||
|
||||
export const airlineModel = z.object({
|
||||
code: z.string(),
|
||||
name: z.string(),
|
||||
imageUrl: z.string().nullable().optional(),
|
||||
});
|
||||
export type Airline = z.infer<typeof airlineModel>;
|
||||
|
||||
export const flightIteneraryModel = z.object({
|
||||
flightId: z.string(),
|
||||
flightNumber: z.string(),
|
||||
airline: airlineModel,
|
||||
departure: iteneraryStationModel,
|
||||
destination: iteneraryStationModel,
|
||||
durationSeconds: z.number(),
|
||||
seatInfo: seatInfoModel,
|
||||
});
|
||||
export type FlightItenerary = z.infer<typeof flightIteneraryModel>;
|
||||
|
||||
export const passengerCountModel = z.object({
|
||||
adults: z.number().int().min(0),
|
||||
children: z.number().int().min(0),
|
||||
});
|
||||
export type PassengerCount = z.infer<typeof passengerCountModel>;
|
||||
|
||||
export function countPassengers(model: PassengerCount) {
|
||||
return model.adults + model.children;
|
||||
}
|
||||
|
||||
export const bagDimensionsModel = z.object({
|
||||
length: z.number(),
|
||||
width: z.number(),
|
||||
height: z.number(),
|
||||
});
|
||||
export type BagDimensions = z.infer<typeof bagDimensionsModel>;
|
||||
|
||||
export const bagDetailsModel = z.object({
|
||||
price: z.number(),
|
||||
weight: z.number(),
|
||||
unit: z.string(),
|
||||
dimensions: bagDimensionsModel,
|
||||
});
|
||||
export type BagDetails = z.infer<typeof bagDetailsModel>;
|
||||
|
||||
export const allBagDetailsModel = z.object({
|
||||
personalBags: bagDetailsModel,
|
||||
handBags: bagDetailsModel,
|
||||
checkedBags: bagDetailsModel,
|
||||
});
|
||||
export type AllBagDetails = z.infer<typeof allBagDetailsModel>;
|
||||
|
||||
// INFO: If you are to array-ificate it, you can just modify the details
|
||||
// key below so that the user's order thing is not disrupted
|
||||
|
||||
export const bagsInfoModel = z.object({
|
||||
includedPersonalBags: z.number().default(1),
|
||||
includedHandBags: z.number().default(0),
|
||||
includedCheckedBags: z.number().default(0),
|
||||
hasHandBagsSupport: z.boolean().default(true),
|
||||
hasCheckedBagsSupport: z.boolean().default(true),
|
||||
details: allBagDetailsModel,
|
||||
});
|
||||
export type BagsInfo = z.infer<typeof bagsInfoModel>;
|
||||
|
||||
export const flightTicketModel = z.object({
|
||||
id: z.number().int(),
|
||||
ticketId: z.string(),
|
||||
|
||||
// For lookup purposes, we need these on the top level
|
||||
departure: z.string(),
|
||||
arrival: z.string(),
|
||||
departureDate: z.coerce.string(),
|
||||
returnDate: z.coerce.string().default(""),
|
||||
dates: z.array(z.string()),
|
||||
|
||||
flightType: z.enum([TicketType.OneWay, TicketType.Return]),
|
||||
flightIteneraries: z.object({
|
||||
outbound: z.array(flightIteneraryModel),
|
||||
inbound: z.array(flightIteneraryModel),
|
||||
}),
|
||||
priceDetails: flightPriceDetailsModel,
|
||||
refundable: z.boolean(),
|
||||
passengerCounts: passengerCountModel,
|
||||
cabinClass: z.string(),
|
||||
bagsInfo: bagsInfoModel,
|
||||
lastAvailable: z.object({ availableSeats: z.number() }),
|
||||
|
||||
shareId: z.string(),
|
||||
checkoutUrl: z.string(),
|
||||
|
||||
isCache: z.boolean().nullish().optional(),
|
||||
refOIds: z.array(z.coerce.number()).nullish().optional(),
|
||||
|
||||
createdAt: z.coerce.string(),
|
||||
updatedAt: z.coerce.string(),
|
||||
});
|
||||
export type FlightTicket = z.infer<typeof flightTicketModel>;
|
||||
|
||||
export const limitedFlightTicketModel = flightTicketModel.pick({
|
||||
id: true,
|
||||
departure: true,
|
||||
arrival: true,
|
||||
departureDate: true,
|
||||
returnDate: true,
|
||||
flightType: true,
|
||||
dates: true,
|
||||
priceDetails: true,
|
||||
passengerCounts: true,
|
||||
cabinClass: true,
|
||||
});
|
||||
export type LimitedFlightTicket = z.infer<typeof limitedFlightTicketModel>;
|
||||
|
||||
// INFO: ticket search models
|
||||
|
||||
export const ticketSearchPayloadModel = z.object({
|
||||
sessionId: z.string(),
|
||||
ticketType: z.enum([TicketType.OneWay, TicketType.Return]),
|
||||
cabinClass: z.enum([
|
||||
CabinClass.Economy,
|
||||
CabinClass.PremiumEconomy,
|
||||
CabinClass.Business,
|
||||
CabinClass.FirstClass,
|
||||
]),
|
||||
departure: z.string().min(3),
|
||||
arrival: z.string().min(3),
|
||||
passengerCounts: passengerCountModel,
|
||||
departureDate: z.coerce.string().min(3),
|
||||
returnDate: z.coerce.string(),
|
||||
loadMore: z.boolean().default(false),
|
||||
meta: z.record(z.string(), z.any()).optional(),
|
||||
couponCode: z.string().optional(),
|
||||
});
|
||||
export type TicketSearchPayload = z.infer<typeof ticketSearchPayloadModel>;
|
||||
|
||||
export const ticketSearchDTO = z.object({
|
||||
sessionId: z.string(),
|
||||
ticketSearchPayload: ticketSearchPayloadModel,
|
||||
providers: z.array(z.string()).optional(),
|
||||
});
|
||||
export type TicketSearchDTO = z.infer<typeof ticketSearchDTO>;
|
||||
Reference in New Issue
Block a user