Skip to content

Instantly share code, notes, and snippets.

@heymonicakay
Last active January 18, 2024 16:38
Show Gist options
  • Save heymonicakay/597a9dbfc8347ec1bbdd30521339171a to your computer and use it in GitHub Desktop.
Save heymonicakay/597a9dbfc8347ec1bbdd30521339171a to your computer and use it in GitHub Desktop.
/**********
Runtime validation
***********/
/**********
shared/types/luna/patient/me
***********/
const DecoratedPatientSchema = z.object(
{
// ... patient properties
personalData: {
firstName: z.string().trim().min(1),
lastName: z.string().trim().min(1),
preferredName: z.string().trim().min(1),
// personal data properties
},
files: {
idCardBack: z.string().trim().min(1),
idCardFront: z.string().trim().min(1)
},
// ... more patient properties
}
)
type DecoratedPatientRes = z.infer<typeof DecoratedPatientSchema>
/*******
server/functions/patient/router/handlers/me
********/
export const getMe = async (_req: Request, res: PxAuthResponse<DecoratedPatientRes>) => {
const { patient } = res.locals
// Get all the data to decorate patient
const files = getFiles(...)
// Decorate patient
patient.files = files
// Run schema validation
try{
const parsedPatientData = DecoratedPatientSchema.parse(patient)
res.status(200).json(parsedPatientData)
} catch{
// handle error
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment