Skip to content

Commit

Permalink
added in a time sort check and fixed some linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SageMar committed Dec 2, 2024
1 parent 034e7b4 commit 4f12d03
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/server/services/csvPipeline/uploadMeters.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@ async function uploadMeters(req, res, filepath, conn) {

// Verify area unit
const areaInput = meter[9];
if (areaInput){
if (areaInput) {
if (!isValidArea(areaInput)){
let msg = `For meter ${meter[0]} the area entry of ${areaInput} is invalid.`;
throw new CSVPipelineError(msg, undefined, 500);
}
}

const timeSortValue = meter[17];
if (timeSortValue) {
if (!isValidTimeSort(timeSortValue)){
let msg = `For meter ${meter[0]} the time sort ${timeSortValue} is invalid.`;
throw new CSVPipelineError(msg, undefined, 500);
}
}

// Verify area unit provided
const areaUnitString = meter[25];
if (areaUnitString) {
Expand Down Expand Up @@ -140,11 +148,10 @@ async function uploadMeters(req, res, filepath, conn) {
throw new CSVPipelineError(
`Meter name of \"${meter[0]}\" got database error of: ${error.message}`, undefined, 500);
}
);
);
}
}
}
catch (error) {
} catch (error) {
throw new CSVPipelineError(`Failed to upload meters due to internal OED Error: ${error.message}`, undefined, 500);
}
}
Expand Down Expand Up @@ -206,7 +213,21 @@ function isValidArea(areaInput) {
function isValidAreaUnit(areaUnit) {
const validTypes = ['feet', 'meters', 'none'];
// must be one of the three values
if (validTypes.includes(areaUnit.toLowerCase())){
if (validTypes.includes(areaUnit)){
return true;
} else {
return false;
}
}

/**
* Checks if the area unit provided is an option
* @param timeSortValue the provided area for the meter
* @returns true or false
*/
function isValidTimeSort(timeSortValue) {
// must be one of the three values
if (timeSortValue == 'increasing' || timeSortValue == 'decreasing'){
return true;
} else {
return false;
Expand All @@ -220,7 +241,7 @@ function isValidAreaUnit(areaUnit) {
*/
function isValidMeterType(meterTypeString) {
const validTypes = ['egauge', 'mamac', 'metasys', 'obvius', 'other'];
if (validTypes.includes(meterTypeString.toLowerCase())){
if (validTypes.includes(meterTypeString)){
return true;
} else {
return false;
Expand Down

0 comments on commit 4f12d03

Please sign in to comment.