diff --git a/apps/Backend/src/storage/index.ts b/apps/Backend/src/storage/index.ts index c41663b..41a732c 100644 --- a/apps/Backend/src/storage/index.ts +++ b/apps/Backend/src/storage/index.ts @@ -910,13 +910,9 @@ export const storage: IStorage = { serviceLines: true, }, }, - transactions: { + serviceLineTransactions: { include: { - serviceLinePayments: { - include: { - serviceLine: true, - }, - }, + 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,13 +941,9 @@ export const storage: IStorage = { serviceLines: true, }, }, - transactions: { + serviceLineTransactions: { include: { - serviceLinePayments: { - include: { - serviceLine: true, - }, - }, + 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,13 +972,9 @@ export const storage: IStorage = { serviceLines: true, }, }, - transactions: { + serviceLineTransactions: { include: { - serviceLinePayments: { - include: { - serviceLine: true, - }, - }, + 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,13 +1005,9 @@ export const storage: IStorage = { serviceLines: true, }, }, - transactions: { + serviceLineTransactions: { include: { - serviceLinePayments: { - include: { - serviceLine: true, - }, - }, + 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,13 +1042,9 @@ export const storage: IStorage = { serviceLines: true, }, }, - transactions: { + serviceLineTransactions: { include: { - serviceLinePayments: { - include: { - serviceLine: true, - }, - }, + 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", })); }, diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index 64dd63d..0154309 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -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]) diff --git a/packages/db/types/payment-types.ts b/packages/db/types/payment-types.ts index 4d96385..fce7576 100644 --- a/packages/db/types/payment-types.ts +++ b/packages/db/types/payment-types.ts @@ -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; // 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<{ - include: { - serviceLinePayments: { - include: { serviceLine: true }; +export type ServiceLineTransactionRecord = + Prisma.ServiceLineTransactionGetPayload<{ + include: { + serviceLine: true; }; - }; -}>; + }>; -// Type for ServiceLinePayment input (used for updates/creates) -export type ServiceLinePayment = z.infer< - typeof ServiceLinePaymentCreateInputObjectSchema ->; - -// Enum for payment +// Enum for payment export type PaymentStatus = z.infer; -export type PaymentMethod = z.infer +export type PaymentMethod = z.infer; // ✅ 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 @@ -78,8 +62,7 @@ export type UpdatePayment = z.infer; // 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,13 +78,9 @@ export type PaymentWithExtras = Prisma.PaymentGetPayload<{ serviceLines: true; }; }; - transactions: { + serviceLineTransactions: { include: { - serviceLinePayments: { - include: { - serviceLine: true; - }; - }; + 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; diff --git a/packages/db/usedSchemas/index.ts b/packages/db/usedSchemas/index.ts index 04d0c0a..2a16023 100644 --- a/packages/db/usedSchemas/index.ts +++ b/packages/db/usedSchemas/index.ts @@ -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' \ No newline at end of file