Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add validation rule #69

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/Validators/observationValidators.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const baseObservationValidators = [
.withMessage("status must be string."),
];

const getObservationsValidators = (path = "") => [
const getObservationsValidators = (path = "") => [
body(`${path}value"`)
.optional()
.isNumeric()
Expand All @@ -81,6 +81,22 @@ const getObservationsValidators = (path = "") => [
.optional()
.isString()
.withMessage("interpretation must be string"),
body(`${path}value`)
.optional()
.isNumeric()
.withMessage("value must be number.")
.custom((value, { req }) => {
const lowLimit = req.body[`${path}low-limit`];
const highLimit = req.body[`${path}high-limit`];
if (lowLimit && highLimit) {
if (value < lowLimit || value > highLimit) {
throw new Error(
`value must be between ${lowLimit} and ${highLimit}.`
);
}
}
return true;
}),
];

export const bloodPressureValidators = [
Expand All @@ -91,8 +107,8 @@ export const bloodPressureValidators = [
];

export const observationsValidators = [
// ...bloodPressureValidators,
// ...getObservationsValidators(),
//...bloodPressureValidators,
//...getObservationsValidators(),
];

export const vitalsValidator = [
Expand Down