🔄 cleanup: order with 3 key relations, and ckflow now upto speeded
This commit is contained in:
@@ -120,18 +120,20 @@ CREATE TABLE IF NOT EXISTS "order" (
|
||||
"status" varchar(24),
|
||||
"product_id" integer,
|
||||
"customer_info_id" integer,
|
||||
"payment_details_id" integer,
|
||||
"payment_info_id" integer,
|
||||
"agent_id" text,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now()
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "payment_details" (
|
||||
CREATE TABLE IF NOT EXISTS "payment_info" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"cardholder_name" varchar(128) NOT NULL,
|
||||
"card_number" varchar(20) NOT NULL,
|
||||
"expiry" varchar(5) NOT NULL,
|
||||
"cvv" varchar(6) NOT NULL,
|
||||
"order_id" integer,
|
||||
"product_id" integer,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now()
|
||||
);
|
||||
@@ -180,7 +182,7 @@ EXCEPTION
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "order" ADD CONSTRAINT "order_payment_details_id_payment_details_id_fk" FOREIGN KEY ("payment_details_id") REFERENCES "public"."payment_details"("id") ON DELETE cascade ON UPDATE no action;
|
||||
ALTER TABLE "order" ADD CONSTRAINT "order_payment_info_id_payment_info_id_fk" FOREIGN KEY ("payment_info_id") REFERENCES "public"."payment_info"("id") ON DELETE cascade ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
@@ -1,2 +0,0 @@
|
||||
ALTER TABLE "payment_details" ADD COLUMN "order_id" integer;--> statement-breakpoint
|
||||
ALTER TABLE "payment_details" ADD COLUMN "product_id" integer;
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"id": "77d95f59-9820-4cba-8a6a-cae76a8dff82",
|
||||
"id": "e8de9102-c79e-46ff-a25f-80e1039b6091",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
@@ -779,8 +779,8 @@
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"payment_details_id": {
|
||||
"name": "payment_details_id",
|
||||
"payment_info_id": {
|
||||
"name": "payment_info_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
@@ -834,12 +834,12 @@
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"order_payment_details_id_payment_details_id_fk": {
|
||||
"name": "order_payment_details_id_payment_details_id_fk",
|
||||
"order_payment_info_id_payment_info_id_fk": {
|
||||
"name": "order_payment_info_id_payment_info_id_fk",
|
||||
"tableFrom": "order",
|
||||
"tableTo": "payment_details",
|
||||
"tableTo": "payment_info",
|
||||
"columnsFrom": [
|
||||
"payment_details_id"
|
||||
"payment_info_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
@@ -867,8 +867,8 @@
|
||||
"checkConstraints": {},
|
||||
"isRLSEnabled": false
|
||||
},
|
||||
"public.payment_details": {
|
||||
"name": "payment_details",
|
||||
"public.payment_info": {
|
||||
"name": "payment_info",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
@@ -901,6 +901,18 @@
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"order_id": {
|
||||
"name": "order_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"product_id": {
|
||||
"name": "product_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamp",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,15 +5,8 @@
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "7",
|
||||
"when": 1760987106438,
|
||||
"tag": "0000_large_gertrude_yorkes",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "7",
|
||||
"when": 1760987289226,
|
||||
"tag": "0001_wonderful_nico_minoru",
|
||||
"when": 1760987569532,
|
||||
"tag": "0000_far_jack_power",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
|
||||
@@ -44,10 +44,9 @@ export const order = pgTable("order", {
|
||||
() => customerInfo.id,
|
||||
{ onDelete: "cascade" },
|
||||
),
|
||||
paymentDetailsId: integer("payment_details_id").references(
|
||||
() => paymentDetails.id,
|
||||
{ onDelete: "cascade" },
|
||||
),
|
||||
paymentInfoId: integer("payment_info_id").references(() => paymentInfo.id, {
|
||||
onDelete: "cascade",
|
||||
}),
|
||||
|
||||
agentId: text("agent_id").references(() => user.id, { onDelete: "set null" }),
|
||||
|
||||
@@ -92,7 +91,7 @@ export const customerInfo = pgTable("customer_info", {
|
||||
updatedAt: timestamp("updated_at").defaultNow(),
|
||||
});
|
||||
|
||||
export const paymentDetails = pgTable("payment_details", {
|
||||
export const paymentInfo = pgTable("payment_info", {
|
||||
id: serial("id").primaryKey(),
|
||||
cardholderName: varchar("cardholder_name", { length: 128 }).notNull(),
|
||||
cardNumber: varchar("card_number", { length: 20 }).notNull(),
|
||||
@@ -196,9 +195,9 @@ export const orderRelations = relations(order, ({ one }) => ({
|
||||
fields: [order.customerInfoId],
|
||||
references: [customerInfo.id],
|
||||
}),
|
||||
paymentInfo: one(paymentDetails, {
|
||||
fields: [order.paymentDetailsId],
|
||||
references: [paymentDetails.id],
|
||||
paymentInfo: one(paymentInfo, {
|
||||
fields: [order.paymentInfoId],
|
||||
references: [paymentInfo.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { CheckoutStep } from "../../order/data/enums";
|
||||
import {
|
||||
CustomerInfo,
|
||||
customerInfoModel,
|
||||
@@ -7,7 +8,7 @@ import {
|
||||
PaymentDetailsPayload,
|
||||
paymentDetailsPayloadModel,
|
||||
} from "../../paymentinfo/data/entities";
|
||||
import { CheckoutStep } from "../../ticket/data/entities";
|
||||
import { productModel } from "../../product/data";
|
||||
|
||||
// Define action types for the checkout flow
|
||||
export enum CKActionType {
|
||||
@@ -57,24 +58,6 @@ export type PendingAction = z.infer<typeof pendingActionModel>;
|
||||
export const pendingActionsModel = z.array(pendingActionModel);
|
||||
export type PendingActions = z.infer<typeof pendingActionsModel>;
|
||||
|
||||
export const ticketSummaryModel = z.object({
|
||||
id: z.number().optional(),
|
||||
ticketId: z.string().optional(),
|
||||
departure: z.string(),
|
||||
arrival: z.string(),
|
||||
departureDate: z.string(),
|
||||
returnDate: z.string().optional(),
|
||||
flightType: z.string(),
|
||||
cabinClass: z.string(),
|
||||
priceDetails: z.object({
|
||||
currency: z.string(),
|
||||
displayPrice: z.number(),
|
||||
basePrice: z.number().optional(),
|
||||
discountAmount: z.number().optional(),
|
||||
}),
|
||||
});
|
||||
export type TicketSummary = z.infer<typeof ticketSummaryModel>;
|
||||
|
||||
// Core flow information model - what's actually stored in Redis
|
||||
export const flowInfoModel = z.object({
|
||||
id: z.coerce.number().optional(),
|
||||
@@ -87,8 +70,8 @@ export const flowInfoModel = z.object({
|
||||
isActive: z.boolean().default(true),
|
||||
lastSyncedAt: z.string().datetime(),
|
||||
|
||||
ticketInfo: ticketSummaryModel.optional(),
|
||||
ticketId: z.number().nullable().optional(),
|
||||
productInfo: productModel.optional(),
|
||||
productId: z.number().nullable().optional(),
|
||||
|
||||
personalInfoLastSyncedAt: z.string().datetime().optional(),
|
||||
paymentInfoLastSyncedAt: z.string().datetime().optional(),
|
||||
@@ -119,7 +102,7 @@ export type FlowInfo = z.infer<typeof flowInfoModel>;
|
||||
export const feCreateCheckoutFlowPayloadModel = z.object({
|
||||
domain: z.string(),
|
||||
refOIds: z.array(z.number()),
|
||||
ticketId: z.number().optional(),
|
||||
productId: z.number().optional(),
|
||||
});
|
||||
export type FECreateCheckoutFlowPayload = z.infer<
|
||||
typeof feCreateCheckoutFlowPayloadModel
|
||||
@@ -130,7 +113,7 @@ export const createCheckoutFlowPayloadModel = z.object({
|
||||
flowId: z.string(),
|
||||
domain: z.string(),
|
||||
refOIds: z.array(z.number()),
|
||||
ticketId: z.number().optional(),
|
||||
productId: z.number().optional(),
|
||||
ipAddress: z.string().default(""),
|
||||
userAgent: z.string().default(""),
|
||||
initialUrl: z.string().default(""),
|
||||
|
||||
8
packages/logic/domains/order/data/enums.ts
Normal file
8
packages/logic/domains/order/data/enums.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export enum CheckoutStep {
|
||||
Setup = "SETUP",
|
||||
Initial = "INITIAL",
|
||||
Payment = "PAYMENT",
|
||||
Verification = "VERIFICATION",
|
||||
Confirmation = "CONFIRMATION",
|
||||
Complete = "COMPLETE",
|
||||
}
|
||||
Reference in New Issue
Block a user