stashing code

This commit is contained in:
user
2025-10-20 17:07:41 +03:00
commit f5b99afc8f
890 changed files with 54823 additions and 0 deletions

View File

@@ -0,0 +1,133 @@
import { paginationModel } from "../../../core/pagination.utils";
import { encodeCursor } from "../../../core/string.utils";
import {
emailAccountModel,
emailAccountPayloadModel,
} from "../../account/data/entities";
import { flightTicketModel } from "../../ticket/data/entities";
import { passengerInfoModel } from "../../passengerinfo/data/entities";
import { z } from "zod";
import { paymentDetailsPayloadModel } from "../../paymentinfo/data/entities";
export enum OrderCreationStep {
ACCOUNT_SELECTION = 0,
TICKET_SELECTION = 1,
PASSENGER_INFO = 2,
SUMMARY = 3,
}
export enum OrderStatus {
PENDING_FULLFILLMENT = "PENDING_FULLFILLMENT",
PARTIALLY_FULFILLED = "PARTIALLY_FULFILLED",
FULFILLED = "FULFILLED",
CANCELLED = "CANCELLED",
}
export const orderModel = z.object({
id: z.coerce.number().int().positive(),
discountAmount: z.coerce.number().min(0),
basePrice: z.coerce.number().min(0),
displayPrice: z.coerce.number().min(0),
orderPrice: z.coerce.number().min(0),
fullfilledPrice: z.coerce.number().min(0),
pricePerPassenger: z.coerce.number().min(0),
status: z.nativeEnum(OrderStatus),
flightTicketInfoId: z.number(),
emailAccountId: z.number().nullish().optional(),
paymentDetailsId: z.number().nullish().optional(),
createdAt: z.coerce.string(),
updatedAt: z.coerce.string(),
});
export type OrderModel = z.infer<typeof orderModel>;
export const limitedOrderWithTicketInfoModel = orderModel
.pick({
id: true,
basePrice: true,
discountAmount: true,
displayPrice: true,
pricePerPassenger: true,
fullfilledPrice: true,
status: true,
})
.merge(
z.object({
flightTicketInfo: flightTicketModel.pick({
id: true,
departure: true,
arrival: true,
departureDate: true,
returnDate: true,
flightType: true,
passengerCounts: true,
}),
}),
);
export type LimitedOrderWithTicketInfoModel = z.infer<
typeof limitedOrderWithTicketInfoModel
>;
export const fullOrderModel = orderModel.merge(
z.object({
flightTicketInfo: flightTicketModel,
emailAccount: emailAccountModel.nullable().optional(),
passengerInfos: z.array(passengerInfoModel).default([]),
}),
);
export type FullOrderModel = z.infer<typeof fullOrderModel>;
export const orderCursorModel = z.object({
firstItemId: z.number(),
lastItemId: z.number(),
query: z.string().default(""),
});
export type OrderCursorModel = z.infer<typeof orderCursorModel>;
export function getDefaultOrderCursor() {
return orderCursorModel.parse({ firstItemId: 0, lastItemId: 0, query: "" });
}
export const paginatedOrderInfoModel = paginationModel.merge(
z.object({ data: z.array(orderModel) }),
);
export type PaginatedOrderInfoModel = z.infer<typeof paginatedOrderInfoModel>;
export function getDefaultPaginatedOrderInfoModel(): PaginatedOrderInfoModel {
return {
data: [],
cursor: encodeCursor<OrderCursorModel>(getDefaultOrderCursor()),
limit: 20,
asc: true,
totalItemCount: 0,
totalPages: 0,
page: 0,
};
}
export const newOrderModel = orderModel.pick({
basePrice: true,
displayPrice: true,
discountAmount: true,
orderPrice: true,
fullfilledPrice: true,
pricePerPassenger: true,
flightTicketInfoId: true,
paymentDetailsId: true,
emailAccountId: true,
});
export type NewOrderModel = z.infer<typeof newOrderModel>;
export const createOrderPayloadModel = z.object({
flightTicketInfo: flightTicketModel.optional(),
flightTicketId: z.number().optional(),
refOIds: z.array(z.number()).nullable().optional(),
paymentDetails: paymentDetailsPayloadModel.optional(),
orderModel: newOrderModel,
emailAccountInfo: emailAccountPayloadModel.optional(),
passengerInfos: z.array(passengerInfoModel),
flowId: z.string().optional(),
});
export type CreateOrderModel = z.infer<typeof createOrderPayloadModel>;