payment checkpoint 3

This commit is contained in:
2025-08-08 00:34:56 +05:30
parent c107c798cf
commit 89897ef2d6
11 changed files with 699 additions and 274 deletions

View File

@@ -202,6 +202,27 @@ router.get("/filter", async (req: Request, res: Response): Promise<any> => {
}
});
// GET /api/payments/:id
router.get("/:id", async (req: Request, res: Response): Promise<any> => {
try {
const userId = req.user?.id;
if (!userId) return res.status(401).json({ message: "Unauthorized" });
const id = parseIntOrError(req.params.id, "Payment ID");
const payment = await storage.getPaymentById(userId, id);
if (!payment)
return res.status(404).json({ message: "Payment not found" });
res.status(200).json(payment);
} catch (err: unknown) {
const message =
err instanceof Error ? err.message : "Failed to retrieve payment";
res.status(500).json({ message });
}
});
// POST /api/payments/:claimId
router.post("/:claimId", async (req: Request, res: Response): Promise<any> => {
try {

View File

@@ -9,12 +9,14 @@ import {
PdfFileUncheckedCreateInputObjectSchema,
PdfGroupUncheckedCreateInputObjectSchema,
PdfCategorySchema,
PaymentUncheckedCreateInputObjectSchema,
PaymentTransactionCreateInputObjectSchema,
ServiceLinePaymentCreateInputObjectSchema,
} from "@repo/db/usedSchemas";
import { z } from "zod";
import { Prisma } from "@repo/db/generated/prisma";
import {
InsertPayment,
Payment,
PaymentWithExtras,
UpdatePayment,
} from "@repo/db/types";
//creating types out of schema auto generated.
type Appointment = z.infer<typeof AppointmentUncheckedCreateInputObjectSchema>;
@@ -158,50 +160,6 @@ export interface ClaimPdfMetadata {
uploadedAt: Date;
}
// Base Payment type
type Payment = z.infer<typeof PaymentUncheckedCreateInputObjectSchema>;
type PaymentTransaction = z.infer<
typeof PaymentTransactionCreateInputObjectSchema
>;
type ServiceLinePayment = z.infer<
typeof ServiceLinePaymentCreateInputObjectSchema
>;
const insertPaymentSchema = (
PaymentUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
).omit({
id: true,
createdAt: true,
updatedAt: true,
});
type InsertPayment = z.infer<typeof insertPaymentSchema>;
const updatePaymentSchema = (
PaymentUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
)
.omit({
id: true,
createdAt: true,
})
.partial();
type UpdatePayment = z.infer<typeof updatePaymentSchema>;
type PaymentWithExtras = Prisma.PaymentGetPayload<{
include: {
transactions: true;
servicePayments: true;
claim: {
include: {
serviceLines: true;
};
};
};
}> & {
patientName: string;
paymentDate: Date;
paymentMethod: string;
};
export interface IStorage {
// User methods
getUser(id: number): Promise<User | undefined>;
@@ -952,8 +910,16 @@ export const storage: IStorage = {
serviceLines: true,
},
},
transactions: true,
servicePayments: true,
transactions: {
include: {
serviceLinePayments: {
include: {
serviceLine: true,
},
},
},
},
updatedBy: true,
},
});
@@ -979,8 +945,16 @@ export const storage: IStorage = {
serviceLines: true,
},
},
transactions: true,
servicePayments: true,
transactions: {
include: {
serviceLinePayments: {
include: {
serviceLine: true,
},
},
},
},
updatedBy: true,
},
});
@@ -1006,8 +980,16 @@ export const storage: IStorage = {
serviceLines: true,
},
},
transactions: true,
servicePayments: true,
transactions: {
include: {
serviceLinePayments: {
include: {
serviceLine: true,
},
},
},
},
updatedBy: true,
},
});
@@ -1035,8 +1017,16 @@ export const storage: IStorage = {
serviceLines: true,
},
},
transactions: true,
servicePayments: true,
transactions: {
include: {
serviceLinePayments: {
include: {
serviceLine: true,
},
},
},
},
updatedBy: true,
},
});
@@ -1068,8 +1058,16 @@ export const storage: IStorage = {
serviceLines: true,
},
},
transactions: true,
servicePayments: true,
transactions: {
include: {
serviceLinePayments: {
include: {
serviceLine: true,
},
},
},
},
updatedBy: true,
},
});