coronasafe / teleicu_middleware

Middleware to help tunnel CCTV Streams and ONVIF APIs for TeleICU.
MIT License
3 stars 14 forks source link

Reject invalid data that are sent to `/update_observations` #67

Open rithviknishad opened 1 year ago

rithviknishad commented 1 year ago

We need to validate the data passed to the /update_observation endpoint.

For example:

If waveform values are beyond the data-highlimit or data-lowlimit they should be rejected.

Amanshenoy008 commented 1 year ago

can I work on this issue

Amanshenoy008 commented 1 year ago

So , I added this validation rules in the ./observationValidator.js

const getObservationsValidators = (path = "") => [

  //  other validation rules  ...

  body(`wavevalue`)
    .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;
    }),
];