payment type and storage udpated

This commit is contained in:
2025-08-09 00:50:57 +05:30
parent b95af918d5
commit 31ed4cd1da
4 changed files with 32 additions and 74 deletions

View File

@@ -910,15 +910,11 @@ export const storage: IStorage = {
serviceLines: true,
},
},
transactions: {
include: {
serviceLinePayments: {
serviceLineTransactions: {
include: {
serviceLine: true,
},
},
},
},
updatedBy: true,
},
});
@@ -929,7 +925,7 @@ export const storage: IStorage = {
...payment,
patientName: payment.claim?.patientName ?? "",
paymentDate: payment.createdAt,
paymentMethod: payment.transactions[0]?.method ?? "OTHER",
paymentMethod: payment.serviceLineTransactions[0]?.method ?? "OTHER",
};
},
@@ -945,15 +941,11 @@ export const storage: IStorage = {
serviceLines: true,
},
},
transactions: {
include: {
serviceLinePayments: {
serviceLineTransactions: {
include: {
serviceLine: true,
},
},
},
},
updatedBy: true,
},
});
@@ -964,7 +956,7 @@ export const storage: IStorage = {
...payment,
patientName: payment.claim?.patientName ?? "",
paymentDate: payment.createdAt,
paymentMethod: payment.transactions[0]?.method ?? "OTHER",
paymentMethod: payment.serviceLineTransactions[0]?.method ?? "OTHER",
};
},
@@ -980,15 +972,11 @@ export const storage: IStorage = {
serviceLines: true,
},
},
transactions: {
include: {
serviceLinePayments: {
serviceLineTransactions: {
include: {
serviceLine: true,
},
},
},
},
updatedBy: true,
},
});
@@ -997,7 +985,7 @@ export const storage: IStorage = {
...payment,
patientName: payment.claim?.patientName ?? "",
paymentDate: payment.createdAt,
paymentMethod: payment.transactions[0]?.method ?? "OTHER",
paymentMethod: payment.serviceLineTransactions[0]?.method ?? "OTHER",
}));
},
@@ -1017,15 +1005,11 @@ export const storage: IStorage = {
serviceLines: true,
},
},
transactions: {
include: {
serviceLinePayments: {
serviceLineTransactions: {
include: {
serviceLine: true,
},
},
},
},
updatedBy: true,
},
});
@@ -1034,7 +1018,7 @@ export const storage: IStorage = {
...payment,
patientName: payment.claim?.patientName ?? "",
paymentDate: payment.createdAt,
paymentMethod: payment.transactions[0]?.method ?? "OTHER",
paymentMethod: payment.serviceLineTransactions[0]?.method ?? "OTHER",
}));
},
@@ -1058,15 +1042,11 @@ export const storage: IStorage = {
serviceLines: true,
},
},
transactions: {
include: {
serviceLinePayments: {
serviceLineTransactions: {
include: {
serviceLine: true,
},
},
},
},
updatedBy: true,
},
});
@@ -1075,7 +1055,7 @@ export const storage: IStorage = {
...payment,
patientName: payment.claim?.patientName ?? "",
paymentDate: payment.createdAt,
paymentMethod: payment.transactions[0]?.method ?? "OTHER",
paymentMethod: payment.serviceLineTransactions[0]?.method ?? "OTHER",
}));
},

View File

@@ -215,7 +215,7 @@ model Payment {
claim Claim @relation(fields: [claimId], references: [id], onDelete: Cascade)
patient Patient @relation(fields: [patientId], references: [id], onDelete: Cascade)
updatedBy User? @relation("PaymentUpdatedBy", fields: [updatedById], references: [id])
transactions ServiceLineTransaction[]
serviceLineTransactions ServiceLineTransaction[]
@@index([id])
@@index([claimId])

View File

@@ -1,12 +1,11 @@
import {
PaymentUncheckedCreateInputObjectSchema,
PaymentTransactionCreateInputObjectSchema,
ServiceLinePaymentCreateInputObjectSchema,
ClaimUncheckedCreateInputObjectSchema,
ServiceLineTransactionCreateInputObjectSchema,
ClaimStatusSchema,
StaffUncheckedCreateInputObjectSchema,
PaymentMethodSchema,
PaymentStatusSchema
PaymentStatusSchema,
} from "@repo/db/usedSchemas";
import { Prisma } from "@repo/db/generated/prisma";
import { z } from "zod";
@@ -18,43 +17,28 @@ import { Decimal } from "decimal.js";
export type Payment = z.infer<typeof PaymentUncheckedCreateInputObjectSchema>;
// Zod input type for creating a transaction
export type PaymentTransactionInput = z.infer<
typeof PaymentTransactionCreateInputObjectSchema
export type ServiceLineTransactionInput = z.infer<
typeof ServiceLineTransactionCreateInputObjectSchema
>;
// Prisma output type for single transaction (fetched with includes)
export type PaymentTransactionRecord = Prisma.PaymentTransactionGetPayload<{
export type ServiceLineTransactionRecord =
Prisma.ServiceLineTransactionGetPayload<{
include: {
serviceLinePayments: {
include: { serviceLine: true };
serviceLine: true;
};
};
}>;
// Type for ServiceLinePayment input (used for updates/creates)
export type ServiceLinePayment = z.infer<
typeof ServiceLinePaymentCreateInputObjectSchema
>;
}>;
// Enum for payment
export type PaymentStatus = z.infer<typeof PaymentStatusSchema>;
export type PaymentMethod = z.infer<typeof PaymentMethodSchema>
export type PaymentMethod = z.infer<typeof PaymentMethodSchema>;
// ✅ Runtime arrays (used in code logic / map / select options)
export const paymentStatusOptions = PaymentStatusSchema.options;
export const paymentMethodOptions = PaymentMethodSchema.options;
// ========== INPUT TYPES ==========
// Used to update individual service line payment
export type PartialServicePaymentInput = {
id: number;
paidAmount: Decimal;
adjustedAmount: Decimal;
notes: string | null;
};
// For creating a new payment
export const insertPaymentSchema = (
PaymentUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
@@ -78,8 +62,7 @@ export type UpdatePayment = z.infer<typeof updatePaymentSchema>;
// Input for updating a payment with new transactions + updated service payments
export type UpdatePaymentInput = {
newTransactions: PaymentTransactionInput[];
servicePayments: PartialServicePaymentInput[];
newTransactions: ServiceLineTransactionInput[];
totalPaid: Decimal;
totalDue: Decimal;
status: PaymentStatus;
@@ -95,15 +78,11 @@ export type PaymentWithExtras = Prisma.PaymentGetPayload<{
serviceLines: true;
};
};
transactions: {
include: {
serviceLinePayments: {
serviceLineTransactions: {
include: {
serviceLine: true;
};
};
};
};
updatedBy: true;
};
}> & {
@@ -140,7 +119,7 @@ export type NewTransactionPayload = {
payerName?: string;
notes?: string;
receivedDate: Date;
serviceLinePayments: {
serviceLineTransactions: {
serviceLineId: number;
paidAmount: number;
adjustedAmount: number;

View File

@@ -10,7 +10,6 @@ export * from '../shared/schemas/objects/PdfGroupUncheckedCreateInput.schema'
export * from '../shared/schemas/enums/PdfCategory.schema'
export * from '../shared/schemas/enums/ClaimStatus.schema'
export * from '../shared/schemas/objects/PaymentUncheckedCreateInput.schema'
export * from '../shared/schemas/objects/PaymentTransactionCreateInput.schema'
export * from '../shared/schemas/objects/ServiceLinePaymentCreateInput.schema'
export * from '../shared/schemas/objects/ServiceLineTransactionCreateInput.schema'
export * from '../shared/schemas/enums/PaymentMethod.schema'
export * from '../shared/schemas/enums/PaymentStatus.schema'