order creation logic fix, refactor & cleanup on admin end

This commit is contained in:
user
2025-10-21 19:20:56 +03:00
parent b6bdb6d7e8
commit f0fa53a4e5
19 changed files with 100 additions and 415 deletions

View File

@@ -30,7 +30,7 @@
}
});
function gototop() {
function goToTop() {
window.scrollTo(0, 0);
return true;
}
@@ -57,10 +57,12 @@
});
</script>
{#if showOtpVerificationForm}
{@const done = gototop()}
<OtpVerificationSection />
{:else}
{@const done2 = gototop()}
<PaymentVerificationLoader />
{/if}
<div class="grid h-full w-full place-items-center gap-4">
{#if showOtpVerificationForm}
{@const done = goToTop()}
<OtpVerificationSection />
{:else}
{@const done2 = goToTop()}
<PaymentVerificationLoader />
{/if}
</div>

View File

@@ -24,9 +24,7 @@ export const orderRouter = createTRPCRouter({
createOrder: publicProcedure
.input(createOrderPayloadModel)
.mutation(async ({ input }) => {
const paymentInfoUC = new PaymentInfoUseCases(
new PaymentInfoRepository(db),
);
const piuc = new PaymentInfoUseCases(new PaymentInfoRepository(db));
const orderController = new OrderController(new OrderRepository(db));
const customerInfoController = getCustomerInfoController();
const productUC = getProductUseCases();
@@ -73,7 +71,7 @@ export const orderRouter = createTRPCRouter({
let paymentInfoId: number | undefined = undefined;
if (input.paymentInfo) {
Logger.info("Creating payment information");
const paymentRes = await paymentInfoUC.createPaymentInfo(
const paymentRes = await piuc.createPaymentInfo(
input.paymentInfo,
);
if (paymentRes.error || !paymentRes.data) {
@@ -98,7 +96,7 @@ export const orderRouter = createTRPCRouter({
if (orderRes.error || !orderRes.data) {
// Cleanup on order creation failure
if (paymentInfoId) {
await paymentInfoUC.deletePaymentInfo(paymentInfoId);
await piuc.deletePaymentInfo(paymentInfoId);
}
await customerInfoController.deleteCustomerInfo(customerInfoId);
return { error: orderRes.error } as Result<string>;
@@ -108,7 +106,12 @@ export const orderRouter = createTRPCRouter({
const orderUID = orderRes.data.uid;
Logger.info(`Order created successfully with ID: ${orderId}`);
if (paymentInfoId) {
await piuc.updatePaymentInfoOrderId(paymentInfoId, orderId);
}
// Update checkout flow state if flowId is provided
//
if (input.flowId) {
Logger.info(
`Updating checkout flow state for flow ${input.flowId}`,

View File

@@ -22,8 +22,8 @@ export class PaymentInfoRepository {
cardholderName: data.cardDetails.cardholderName,
expiry: data.cardDetails.expiry,
cvv: data.cardDetails.cvv,
flightTicketInfoId: data.flightTicketInfoId,
productId: data.productId,
orderId: data.orderId,
createdAt: new Date(),
updatedAt: new Date(),
})
@@ -45,6 +45,20 @@ export class PaymentInfoRepository {
return { data: parsed.data };
}
async updatePaymentInfoOrderId(
id: number,
oid: number,
): Promise<Result<number>> {
Logger.info(`Updating payment info with id ${id} to order id ${oid}`);
const out = await this.db
.update(paymentInfo)
.set({ orderId: oid })
.where(eq(paymentInfo.id, id))
.execute();
Logger.debug(out);
return { data: id };
}
async deletePaymentInfo(id: number): Promise<Result<boolean>> {
Logger.info(`Deleting payment info with id ${id}`);
const out = await this.db

View File

@@ -16,6 +16,10 @@ export class PaymentInfoUseCases {
return this.repo.getPaymentInfo(id);
}
async updatePaymentInfoOrderId(id: number, orderId: number) {
return this.repo.updatePaymentInfoOrderId(id, orderId);
}
async deletePaymentInfo(id: number) {
return this.repo.deletePaymentInfo(id);
}