fix(insuranceId space issue)

This commit is contained in:
2025-10-04 01:31:14 +05:30
parent f0657e78f2
commit 7920f40eb2
4 changed files with 95 additions and 10 deletions

View File

@@ -1,14 +1,44 @@
import { PatientUncheckedCreateInputObjectSchema } from "@repo/db/usedSchemas";
import {z} from "zod";
import { z } from "zod";
export type Patient = z.infer<typeof PatientUncheckedCreateInputObjectSchema>;
export const insuranceIdSchema = z.preprocess(
(val) => {
if (val === undefined || val === null) return undefined;
// Accept numbers and strings
if (typeof val === "number") {
return String(val).replace(/\s+/g, "");
}
if (typeof val === "string") {
const cleaned = val.replace(/\s+/g, "");
if (cleaned === "") return undefined;
return cleaned;
}
return val;
},
// After preprocess, require digits-only string (or optional nullable)
z
.string()
.regex(/^\d+$/, { message: "Insurance ID must contain only digits" })
.min(1)
.max(32)
.optional()
.nullable()
);
export const insertPatientSchema = (
PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
).omit({
id: true,
createdAt: true,
});
)
.omit({
id: true,
createdAt: true,
})
.extend({
insuranceId: insuranceIdSchema, // enforce numeric insuranceId
});
export type InsertPatient = z.infer<typeof insertPatientSchema>;
export const updatePatientSchema = (
@@ -19,6 +49,9 @@ export const updatePatientSchema = (
createdAt: true,
userId: true,
})
.partial();
.partial()
.extend({
insuranceId: insuranceIdSchema, // enforce numeric insuranceId
});
export type UpdatePatient = z.infer<typeof updatePatientSchema>;
export type UpdatePatient = z.infer<typeof updatePatientSchema>;