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

Reject invalid data that are sent to /update_observations #67

Open
rithviknishad opened this issue May 29, 2023 · 2 comments
Open

Reject invalid data that are sent to /update_observations #67

rithviknishad opened this issue May 29, 2023 · 2 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@rithviknishad
Copy link
Member

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.

@rithviknishad rithviknishad added the good first issue Good for newcomers label May 30, 2023
@Amanshenoy008
Copy link

can I work on this issue

@Amanshenoy008
Copy link

Amanshenoy008 commented May 30, 2023

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;
    }),
];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants