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,78 @@
import { getRedisInstance } from "$lib/server/redis";
import { isTimestampMoreThan1MinAgo } from "@pkg/logic/core/date.utils";
import type {
CreateCheckoutFlowPayload,
FlowInfo,
PaymentFlowStepPayload,
PrePaymentFlowStepPayload,
} from "../data/entities";
import { CheckoutFlowRepository } from "../data/repository";
import type { PassengerPII } from "$lib/domains/passengerinfo/data/entities";
import type { PaymentDetailsPayload } from "$lib/domains/paymentinfo/data/entities";
import { db } from "@pkg/db";
export class CheckoutFlowUseCases {
constructor(private repo: CheckoutFlowRepository) {}
async createFlow(payload: CreateCheckoutFlowPayload) {
return this.repo.createFlow(payload);
}
async getFlowInfo(flowId: string) {
const out = await this.repo.getFlowInfo(flowId);
if (out.error || !out.data) {
return out;
}
if (isTimestampMoreThan1MinAgo(out.data.lastPinged)) {
await this.updateFlowState(flowId, {
...out.data,
lastPinged: new Date().toISOString(),
});
}
return out;
}
async updateFlowState(id: string, state: FlowInfo) {
return this.repo.updateFlowState(id, state);
}
async cleanupFlow(id: string, other: any) {
return this.repo.cleanupFlow(id, other);
}
async goBackToInitialStep(flowId: string) {
return this.repo.goBackToInitialStep(flowId);
}
async executePrePaymentStep(
flowId: string,
payload: PrePaymentFlowStepPayload,
) {
return this.repo.executePrePaymentStep(flowId, payload);
}
async executePaymentStep(flowId: string, payload: PaymentFlowStepPayload) {
return this.repo.executePaymentStep(flowId, payload);
}
async syncPersonalInfo(flowId: string, personalInfo: PassengerPII) {
return this.repo.syncPersonalInfo(flowId, personalInfo);
}
async syncPaymentInfo(flowId: string, paymentInfo: PaymentDetailsPayload) {
return this.repo.syncPaymentInfo(flowId, paymentInfo);
}
async ping(flowId: string) {
return this.repo.ping(flowId);
}
async areCheckoutAlreadyLiveForOrder(refOids: number[]) {
return this.repo.areCheckoutAlreadyLiveForOrder(refOids);
}
}
export function getCKUseCases() {
const repo = new CheckoutFlowRepository(db);
return new CheckoutFlowUseCases(repo);
}