128 lines
3.6 KiB
TypeScript
128 lines
3.6 KiB
TypeScript
import { z } from "zod";
|
|
import { paginationModel } from "../../../core/pagination.utils";
|
|
import { encodeCursor } from "../../../core/string.utils";
|
|
import { customerInfoModel } from "../../customerinfo/data";
|
|
import { paymentDetailsPayloadModel } from "../../paymentinfo/data/entities";
|
|
import { flightTicketModel } from "../../ticket/data/entities";
|
|
|
|
export enum OrderCreationStep {
|
|
ACCOUNT_SELECTION = 0,
|
|
TICKET_SELECTION = 1,
|
|
CUSTOMER_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),
|
|
pricePerCustomer: 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,
|
|
pricePerCustomer: 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,
|
|
customerInfos: z.array(customerInfoModel).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,
|
|
pricePerCustomer: 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,
|
|
customerInfos: z.array(customerInfoModel),
|
|
flowId: z.string().optional(),
|
|
});
|
|
export type CreateOrderModel = z.infer<typeof createOrderPayloadModel>;
|