🔄 cleanup: more order logic cleanup on the admin side mostly

This commit is contained in:
user
2025-10-20 22:39:00 +03:00
parent 10bcbf982a
commit 4ae1957a88
18 changed files with 375 additions and 221 deletions

View File

@@ -1,5 +1,5 @@
import type { CustomerInfo } from "$lib/domains/passengerinfo/data/entities";
import type { PaymentDetailsPayload } from "$lib/domains/paymentinfo/data/entities";
import type { PaymentInfoPayload } from "$lib/domains/paymentinfo/data/entities";
import { CheckoutStep } from "$lib/domains/ticket/data/entities";
import type { Database } from "@pkg/db";
import { and, eq } from "@pkg/db";
@@ -254,7 +254,7 @@ export class CheckoutFlowRepository {
async syncPaymentInfo(
flowId: string,
paymentInfo: PaymentDetailsPayload,
paymentInfo: PaymentInfoPayload,
): Promise<Result<boolean>> {
try {
const existingSession = await this.db

View File

@@ -3,8 +3,8 @@ import {
type CustomerInfo,
} from "$lib/domains/passengerinfo/data/entities";
import {
paymentDetailsPayloadModel,
type PaymentDetailsPayload,
paymentInfoPayloadModel,
type PaymentInfoPayload,
} from "$lib/domains/paymentinfo/data/entities";
import { CheckoutStep } from "$lib/domains/ticket/data/entities";
import { createTRPCRouter, publicProcedure } from "$lib/trpc/t";
@@ -86,7 +86,7 @@ export const ckflowRouter = createTRPCRouter({
.mutation(async ({ input }) => {
return getCKUseCases().syncPaymentInfo(
input.flowId,
input.paymentInfo as PaymentDetailsPayload,
input.paymentInfo as PaymentInfoPayload,
);
}),
@@ -119,7 +119,7 @@ export const ckflowRouter = createTRPCRouter({
flowId: z.string(),
payload: z.object({
personalInfo: customerInfoModel.optional(),
paymentInfo: paymentDetailsPayloadModel.optional(),
paymentInfo: paymentInfoPayloadModel.optional(),
}),
}),
)

View File

@@ -1,5 +1,5 @@
import type { CustomerInfo } from "$lib/domains/passengerinfo/data/entities";
import type { PaymentDetailsPayload } from "$lib/domains/paymentinfo/data/entities";
import type { PaymentInfoPayload } from "$lib/domains/paymentinfo/data/entities";
import { db } from "@pkg/db";
import { isTimestampMoreThan1MinAgo } from "@pkg/logic/core/date.utils";
import type {
@@ -58,7 +58,7 @@ export class CheckoutFlowUseCases {
return this.repo.syncPersonalInfo(flowId, personalInfo);
}
async syncPaymentInfo(flowId: string, paymentInfo: PaymentDetailsPayload) {
async syncPaymentInfo(flowId: string, paymentInfo: PaymentInfoPayload) {
return this.repo.syncPaymentInfo(flowId, paymentInfo);
}

View File

@@ -11,7 +11,7 @@ import {
type CustomerInfo,
} from "$lib/domains/passengerinfo/data/entities";
import { passengerInfoVM } from "$lib/domains/passengerinfo/view/passenger.info.vm.svelte";
import type { PaymentDetailsPayload } from "$lib/domains/paymentinfo/data/entities";
import type { PaymentInfoPayload } from "$lib/domains/paymentinfo/data/entities";
import { PaymentMethod } from "$lib/domains/paymentinfo/data/entities";
import {
CheckoutStep,
@@ -302,7 +302,7 @@ export class CKFlowViewModel {
}
}
async syncPaymentInfo(paymentInfo: PaymentDetailsPayload) {
async syncPaymentInfo(paymentInfo: PaymentInfoPayload) {
if (!this.flowId || !this.setupDone || !paymentInfo.cardDetails) {
return;
}

View File

@@ -3,9 +3,9 @@ import { paymentInfo } from "@pkg/db/schema";
import { Logger } from "@pkg/logger";
import type { Result } from "@pkg/result";
import {
paymentDetailsModel,
type PaymentDetails,
type PaymentDetailsPayload,
paymentInfoModel,
type PaymentInfo,
type PaymentInfoPayload,
} from "./entities";
export class PaymentInfoRepository {
@@ -14,9 +14,7 @@ export class PaymentInfoRepository {
this.db = db;
}
async createPaymentInfo(
data: PaymentDetailsPayload,
): Promise<Result<number>> {
async createPaymentInfo(data: PaymentInfoPayload): Promise<Result<number>> {
const out = await this.db
.insert(paymentInfo)
.values({
@@ -34,12 +32,12 @@ export class PaymentInfoRepository {
return { data: out[0]?.id };
}
async getPaymentInfo(id: number): Promise<Result<PaymentDetails>> {
async getPaymentInfo(id: number): Promise<Result<PaymentInfo>> {
Logger.info(`Getting payment info with id ${id}`);
const out = await this.db.query.paymentInfo.findFirst({
where: eq(paymentInfo.id, id),
});
const parsed = paymentDetailsModel.safeParse(out);
const parsed = paymentInfoModel.safeParse(out);
if (parsed.error) {
Logger.error(parsed.error);
return {};

View File

@@ -1,4 +1,4 @@
import type { PaymentDetailsPayload } from "../data/entities";
import type { PaymentInfoPayload } from "../data/entities";
import type { PaymentInfoRepository } from "../data/repository";
export class PaymentInfoUseCases {
@@ -8,7 +8,7 @@ export class PaymentInfoUseCases {
this.repo = repo;
}
async createPaymentInfo(payload: PaymentDetailsPayload) {
async createPaymentInfo(payload: PaymentInfoPayload) {
return this.repo.createPaymentInfo(payload);
}

View File

@@ -2,7 +2,7 @@ import { ckFlowVM } from "$lib/domains/ckflow/view/ckflow.vm.svelte";
import { newOrderModel } from "$lib/domains/order/data/entities";
import { passengerInfoVM } from "$lib/domains/passengerinfo/view/passenger.info.vm.svelte";
import {
paymentDetailsPayloadModel,
paymentInfoPayloadModel,
PaymentMethod,
} from "$lib/domains/paymentinfo/data/entities";
import { trpcApiStore } from "$lib/stores/api";
@@ -105,7 +105,7 @@ class TicketCheckoutViewModel {
return false;
}
const pInfoParsed = paymentDetailsPayloadModel.safeParse({
const pInfoParsed = paymentInfoPayloadModel.safeParse({
method: PaymentMethod.Card,
cardDetails: paymentInfoVM.cardDetails,
flightTicketInfoId: ticket.id,