Warn against invalid column headers being used, fail gracefully if ones

are present
This commit is contained in:
2022-11-29 18:41:41 +01:00
parent 5146305caf
commit c04d63e026
4 changed files with 20 additions and 5 deletions

View File

@ -44,6 +44,7 @@ class CsvxmlValidator {
validate() {
this.validateMandatoryTagsPresent();
this.validateInvalidTagsPresent();
this.checkDuplicateInvNos();
this.checkDependentColumns();
this.checkControlledLists();
@ -73,6 +74,18 @@ class CsvxmlValidator {
}
validateInvalidTagsPresent() {
const headers = Object.keys(this.toValidate[0]);
for (let header of headers) {
if (this.fieldList[header] === undefined) {
this.errors.parsing.push("Invalid column " + header + " detected! Please remove this column or use the appropriate name!");
}
}
}
checkDuplicateInvNos() {
let invNoEncountered = [];
@ -107,6 +120,7 @@ class CsvxmlValidator {
for (let fieldName in line) {
if (line[fieldName] === '') continue;
if (this.fieldList[fieldName] === undefined) continue; // This may be the case if invalid fields are present
const dependencies = this.fieldList[fieldName].dependsOn;
if (dependencies === undefined) continue;