a.... LOT of Refactoring ~ 30% done???

This commit is contained in:
user
2025-10-21 15:44:16 +03:00
parent 5f4e9fc7fc
commit c0df8cae57
27 changed files with 586 additions and 746 deletions

View File

@@ -1,4 +1,7 @@
import { page } from "$app/state";
import { checkoutVM } from "$lib/domains/checkout/checkout.vm.svelte";
import { billingDetailsVM } from "$lib/domains/checkout/payment-info-section/billing.details.vm.svelte";
import { paymentInfoVM } from "$lib/domains/checkout/payment-info-section/payment.info.vm.svelte";
import {
CKActionType,
SessionOutcome,
@@ -6,21 +9,16 @@ import {
type PendingAction,
type PendingActions,
} from "$lib/domains/ckflow/data/entities";
import type { CustomerInfoModel } from "$lib/domains/customerinfo/data";
import {
customerInfoModel,
type CustomerInfo,
} from "$lib/domains/passengerinfo/data/entities";
CheckoutStep,
type OrderPriceDetailsModel,
} from "$lib/domains/order/data/entities";
import { customerInfoModel } from "$lib/domains/passengerinfo/data/entities";
import { passengerInfoVM } from "$lib/domains/passengerinfo/view/passenger.info.vm.svelte";
import type { PaymentInfoPayload } from "$lib/domains/paymentinfo/data/entities";
import { PaymentMethod } from "$lib/domains/paymentinfo/data/entities";
import {
CheckoutStep,
type FlightPriceDetails,
} from "$lib/domains/ticket/data/entities";
import { flightTicketStore } from "$lib/domains/ticket/data/store";
import { checkoutVM } from "$lib/domains/ticket/view/checkout/checkout.vm.svelte";
import { billingDetailsVM } from "$lib/domains/ticket/view/checkout/payment-info-section/billing.details.vm.svelte";
import { paymentInfoVM } from "$lib/domains/ticket/view/checkout/payment-info-section/payment.info.vm.svelte";
import { productStore } from "$lib/domains/product/store";
import { trpcApiStore } from "$lib/stores/api";
import { ClientLogger } from "@pkg/logger/client";
import { toast } from "svelte-sonner";
@@ -185,7 +183,7 @@ export class CKFlowViewModel {
private paymentInfoDebounceTimer: NodeJS.Timeout | null = null;
syncInterval = 300; // 300ms debounce for syncing
updatedPrices = $state<FlightPriceDetails | undefined>(undefined);
updatedPrices = $state<OrderPriceDetailsModel | undefined>(undefined);
constructor() {
this.actionRunner = new ActionRunner();
@@ -216,17 +214,10 @@ export class CKFlowViewModel {
return;
}
const ticket = get(flightTicketStore);
const refOIds = ticket.refOIds;
if (!refOIds) {
this.setupDone = true;
return; // Since we don't have any attached order(s), we don't need to worry about this dude
}
const info = await api.ckflow.initiateCheckout.mutate({
domain: window.location.hostname,
refOIds,
ticketId: ticket.id,
refOIds: [],
productId: get(productStore)?.id,
});
if (info.error) {
@@ -236,7 +227,7 @@ export class CKFlowViewModel {
if (!info.data) {
toast.error("Error while creating checkout flow", {
description: "Try refreshing page or search for ticket again",
description: "Try refreshing page or contact us",
});
return;
}
@@ -248,7 +239,7 @@ export class CKFlowViewModel {
this.setupDone = true;
}
debouncePersonalInfoSync(personalInfo: CustomerInfo) {
debouncePersonalInfoSync(personalInfo: CustomerInfoModel) {
this.clearPersonalInfoDebounce();
this.personalInfoDebounceTimer = setTimeout(() => {
this.syncPersonalInfo(personalInfo);
@@ -262,9 +253,10 @@ export class CKFlowViewModel {
this.paymentInfoDebounceTimer = setTimeout(() => {
const paymentInfo = {
cardDetails: paymentInfoVM.cardDetails,
flightTicketInfoId: get(flightTicketStore).id,
method: PaymentMethod.Card,
};
orderId: -1,
productId: get(productStore)?.id,
} as PaymentInfoPayload;
this.syncPaymentInfo(paymentInfo);
}, this.syncInterval);
}
@@ -276,12 +268,12 @@ export class CKFlowViewModel {
);
}
isPersonalInfoValid(personalInfo: CustomerInfo): boolean {
isPersonalInfoValid(personalInfo: CustomerInfoModel): boolean {
const parsed = customerInfoModel.safeParse(personalInfo);
return !parsed.error && !!parsed.data;
}
async syncPersonalInfo(personalInfo: CustomerInfo) {
async syncPersonalInfo(personalInfo: CustomerInfoModel) {
if (!this.flowId || !this.setupDone) {
return;
}
@@ -546,7 +538,7 @@ export class CKFlowViewModel {
const out = await api.ckflow.executePrePaymentStep.mutate({
flowId: this.flowId!,
payload: {
initialUrl: get(flightTicketStore).checkoutUrl,
initialUrl: "",
personalInfo: primaryPassengerInfo,
},
});
@@ -570,9 +562,10 @@ export class CKFlowViewModel {
const paymentInfo = {
cardDetails: paymentInfoVM.cardDetails,
flightTicketInfoId: get(flightTicketStore).id,
method: PaymentMethod.Card,
};
orderId: -1,
productId: get(productStore)?.id,
} as PaymentInfoPayload;
const out = await api.ckflow.executePaymentStep.mutate({
flowId: this.flowId!,