Last active
January 18, 2024 16:38
-
-
Save heymonicakay/597a9dbfc8347ec1bbdd30521339171a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********** | |
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