Skip to content

Commit

Permalink
added time zone validation
Browse files Browse the repository at this point in the history
  • Loading branch information
SageMar committed Dec 3, 2024
2 parents 6c612b8 + 143a96d commit 30d213e
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/server/services/csvPipeline/uploadMeters.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ async function uploadMeters(req, res, filepath, conn) {
//validation for boolean values
validateBooleanFields(meter, i);

// Validate min and max values
validateMinMaxValues(meter, i);



// First verify GPS is okay
// This assumes that the sixth column is the GPS as order is assumed for now in a GPS file.
Expand Down Expand Up @@ -328,4 +332,25 @@ function validateBooleanFields(meter, rowIndex) {



module.exports = uploadMeters;
function validateMinMaxValues(meter, rowIndex) {
const minValue = Number(meter[27]);
const maxValue = Number(meter[28]);

if (
isNaN(minValue) ||
isNaN(maxValue) ||
minValue < -9007199254740991 ||
maxValue > 9007199254740991 ||
minValue >= maxValue
) {
throw new CSVPipelineError(
`Invalid min/max values in row ${rowIndex + 1}: min="${meter[27]}", max="${meter[28]}". ` +
`Min or/and max must be a number larger than -9007199254740991, and less then 9007199254740991, and min must be less than max.`,
undefined,
500
);
}
}


module.exports = uploadMeters;

0 comments on commit 30d213e

Please sign in to comment.