refactor: more legacy code replaced more on the model and a bit on the admin side

This commit is contained in:
user
2025-10-20 22:08:45 +03:00
parent 2fdb934ec9
commit 2ed74c267d
33 changed files with 1160 additions and 11574 deletions

View File

@@ -3,17 +3,19 @@ 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";
import { productModel } from "../../product/data";
export enum OrderCreationStep {
ACCOUNT_SELECTION = 0,
TICKET_SELECTION = 1,
// TODO: only keep these remove the above 2 steps
CUSTOMER_INFO = 2,
PAYMENT = 2,
SUMMARY = 3,
}
export enum OrderStatus {
PENDING_FULLFILLMENT = "PENDING_FULLFILLMENT",
PENDING_FULFILLMENT = "PENDING_FULFILLMENT",
PARTIALLY_FULFILLED = "PARTIALLY_FULFILLED",
FULFILLED = "FULFILLED",
CANCELLED = "CANCELLED",
@@ -27,13 +29,12 @@ export const orderModel = z.object({
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(),
productId: z.number(),
customerInfoId: z.number().nullish().optional(),
emailAccountId: z.number().nullish().optional(),
paymentDetailsId: z.number().nullish().optional(),
createdAt: z.coerce.string(),
@@ -41,37 +42,34 @@ export const orderModel = z.object({
});
export type OrderModel = z.infer<typeof orderModel>;
export const limitedOrderWithTicketInfoModel = orderModel
export const limitedOrderWithProductModel = orderModel
.pick({
id: true,
basePrice: true,
discountAmount: true,
displayPrice: true,
pricePerCustomer: true,
fullfilledPrice: true,
status: true,
})
.merge(
z.object({
flightTicketInfo: flightTicketModel.pick({
product: productModel.pick({
id: true,
departure: true,
arrival: true,
departureDate: true,
returnDate: true,
flightType: true,
passengerCounts: true,
title: true,
description: true,
price: true,
discountPrice: true,
}),
}),
);
export type LimitedOrderWithTicketInfoModel = z.infer<
typeof limitedOrderWithTicketInfoModel
export type LimitedOrderWithProductModel = z.infer<
typeof limitedOrderWithProductModel
>;
export const fullOrderModel = orderModel.merge(
z.object({
flightTicketInfo: flightTicketModel,
customerInfos: z.array(customerInfoModel).default([]),
product: productModel,
customerInfo: customerInfoModel.optional().nullable(),
}),
);
export type FullOrderModel = z.infer<typeof fullOrderModel>;
@@ -108,20 +106,18 @@ export const newOrderModel = orderModel.pick({
discountAmount: true,
orderPrice: true,
fullfilledPrice: true,
pricePerCustomer: true,
flightTicketInfoId: true,
productId: true,
customerInfoId: 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(),
product: productModel.optional(),
productId: z.number().optional(),
customerInfo: customerInfoModel,
paymentDetails: paymentDetailsPayloadModel.optional(),
orderModel: newOrderModel,
customerInfos: z.array(customerInfoModel),
flowId: z.string().optional(),
});
export type CreateOrderModel = z.infer<typeof createOrderPayloadModel>;