Skip to content

Commit

Permalink
Merge pull request #3034 from bcgov/batch_validators
Browse files Browse the repository at this point in the history
validate calculation type and herbicide type when application method …
  • Loading branch information
micheal-w-wells authored Jan 3, 2024
2 parents 6f8624f + 5f8d246 commit 9a7789f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
37 changes: 37 additions & 0 deletions api/src/utils/batch/shared-columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,43 @@ export const GranularHerbicideRate = (row): RowValidationResult => {
};
};

export const ApplicationMethodType = (row): RowValidationResult => {
let valid = true;
const fields = ['Chemical Treatment (No Tank Mix) - Application Method', 'Chemical Treatment - Calculation Type'];
const rowData = row.data;
const validationMessages = [];

const applicationMethod = rowData[`Chemical Treatment (No Tank Mix) - Application Method`]?.parsedValue;
const applicationMethodFriendly = rowData[`Chemical Treatment (No Tank Mix) - Application Method`]?.friendlyValue;
const calculationType = rowData[`Chemical Treatment - Calculation Type`]?.parsedValue;
const herbicideType = rowData[`Herbicide - 1 - Type`]?.parsedValue;
const directMethods = ['BBA', 'CIN', 'CSP', 'SIN', 'WCK'];

if (directMethods.includes(applicationMethod) && calculationType === 'PAR') {
valid = false;
validationMessages.push({
severity: 'error',
messageTitle: 'Invalid value',
messageDetail: `Calculation Type must be Dilution when Application Method is ${applicationMethodFriendly}.`
});
}

if (directMethods.includes(applicationMethod) && herbicideType === 'G') {
valid = false;
validationMessages.push({
severity: 'error',
messageTitle: 'Invalid value',
messageDetail: `Herbicide Type must be Liquid when Application Method is ${applicationMethodFriendly}.`
});
}

return {
valid,
validationMessages,
appliesToFields: fields
};
};

export const ChemicalPlantTreatmentInformation = [
new TemplateColumnBuilder(
'Chemical Treatment - Service License',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Template, TemplateColumnBuilder } from '../definitions';
import {
ActivityPersonsWithApplicatorLicense,
ApplicationMethodType,
ApplicationMethodValidator,
BasicInformation,
BasicInformationRowValidators,
Expand Down Expand Up @@ -74,6 +75,7 @@ TreatmentChemicalAquaticPlant.rowValidators = [
PmpValidator,
WindDirectionValidator,
ApplicationMethodValidator,
ApplicationMethodType,
GranularHerbicideRate
];
export { TreatmentChemicalAquaticPlant };
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Template, TemplateColumnBuilder } from '../definitions';
import {
ActivityPersonsWithApplicatorLicense,
ApplicationMethodType,
ApplicationMethodValidator,
BasicInformation,
BasicInformationRowValidators,
Expand Down Expand Up @@ -74,6 +75,7 @@ TreatmentChemicalAquaticPlantTemp.rowValidators = [
...ChemTreatmentValidators,
PmpValidator,
WindDirectionValidator,
ApplicationMethodType,
ApplicationMethodValidator,
GranularHerbicideRate
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PmpValidator,
ProjectInformation,
WindDirectionValidator,
ApplicationMethodType,
ApplicationMethodValidator,
GranularHerbicideRate
} from '../shared-columns';
Expand Down Expand Up @@ -72,6 +73,7 @@ TreatmentChemicalTerrestrialPlant.rowValidators = [
...ChemTreatmentValidators,
PmpValidator,
WindDirectionValidator,
ApplicationMethodType,
ApplicationMethodValidator,
GranularHerbicideRate
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PmpValidator,
ProjectInformation,
WindDirectionValidator,
ApplicationMethodType,
ApplicationMethodValidator,
GranularHerbicideRate
} from '../shared-columns';
Expand Down Expand Up @@ -73,6 +74,7 @@ TreatmentChemicalTerrestrialPlantTemp.rowValidators = [
...ChemTreatmentValidators,
PmpValidator,
WindDirectionValidator,
ApplicationMethodType,
ApplicationMethodValidator,
GranularHerbicideRate
];
Expand Down

0 comments on commit 9a7789f

Please sign in to comment.