Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1483 from NMDSdevopsServiceAdm/rel_v1.13_hotfix
Browse files Browse the repository at this point in the history
Rel v1.13 hotfix to Live branch for pre prod
NMDSdevopsServiceAdm authored Sep 20, 2019
2 parents e39faed + a08d6db commit db21023
Showing 2 changed files with 23 additions and 15 deletions.
27 changes: 16 additions & 11 deletions server/models/classes/establishment/properties/staffProperty.js
Original file line number Diff line number Diff line change
@@ -12,18 +12,23 @@ exports.StaffProperty = class StaffProperty extends ChangePropertyPrototype {

// concrete implementations
async restoreFromJson(document) {
if (document.numberOfStaff !== null) {
const givenStaff = isNaN(parseInt(document.numberOfStaff, 10)) ? null : parseInt(document.numberOfStaff, 10);
const MAX_STAFF=999;
const MIN_STAFF=0;
if (givenStaff !== null &&
givenStaff >= MIN_STAFF &&
givenStaff <= MAX_STAFF) {
this.property = givenStaff;
} else {
this.property = null;
}
if (/^-?[0-9]+$/.test(String(document.numberOfStaff))) {
const givenStaff = parseInt(document.numberOfStaff, 10);
const MAX_STAFF = 999;
const MIN_STAFF = 0;

//if document.numberOfStaff is numeric it must be in range
if (givenStaff >= MIN_STAFF && givenStaff <= MAX_STAFF) {
this.property = givenStaff;
}
else {
this.property = null;
}
}
else if(document.numberOfStaff) {
//any other non falsy value fails validation
this.property = null;
}
}

restorePropertyFromSequelize(document) {
11 changes: 7 additions & 4 deletions server/routes/establishments/bulkUpload.js
Original file line number Diff line number Diff line change
@@ -375,7 +375,6 @@ router.route('/uploaded').put(async (req, res) => {
if(importedTraining){
const trainingCsvValidator = new CsvTrainingValidator(importedTraining[firstRow], firstLineNumber);
if(trainingCsvValidator.preValidate(trainingHeaders)){
console.log("WA DEBUG - prevalidated training - ", importedTraining)
// count records and update metadata
trainingMetadata.records = importedTraining.length;
metadataS3Promises.push(uploadAsJSON(username, establishmentId, trainingMetadata, `${establishmentId}/latest/${trainingMetadata.filename}.metadata.json`));
@@ -1051,7 +1050,7 @@ const validateBulkUploadFiles = async (commit, username , establishmentId, isPar
myTrainings.forEach(thisTraingRecord => {

const establishmentKeyNoWhitespace = (thisTraingRecord.localeStId || '').replace(/\s/g, "");
const workerKeyNoWhitespace = (thisTraingRecord.localeStId + thisTraingRecord.uniqueWorkerId).replace(/\s/g, "");
const workerKeyNoWhitespace = ((thisTraingRecord.localeStId || '') + (thisTraingRecord.uniqueWorkerId || '')).replace(/\s/g, "");

if (!allEstablishmentsByKey[establishmentKeyNoWhitespace]) {
// not found the associated establishment
@@ -1072,10 +1071,14 @@ const validateBulkUploadFiles = async (commit, username , establishmentId, isPar
const foundWorkerByLineNumber = allWorkersByKey[workerKeyNoWhitespace];
const knownWorker = foundWorkerByLineNumber ? myAPIWorkers[foundWorkerByLineNumber] : null;

// training cross-validation against worker's date of birth (DOB) can only be applied, if:
// 1. the associated Worker can be matched
// 2. the worker has DOB defined (it's not a mandatory property)
const trainingCompletedDate = moment.utc(thisTraingRecord._currentLine.DATECOMPLETED, "DD-MM-YYYY")
const workerDob = moment.utc(workersKeyed[workerKeyNoWhitespace].DOB, "DD-MM-YYYY")
const foundAssociatedWorker = workersKeyed[workerKeyNoWhitespace];
const workerDob = foundAssociatedWorker && foundAssociatedWorker.DOB ? moment.utc(workersKeyed[workerKeyNoWhitespace].DOB, "DD-MM-YYYY") : null;

if (workerDob.isValid() && trainingCompletedDate.diff(workerDob, 'years') < 14 ) {
if (workerDob && workerDob.isValid() && trainingCompletedDate.diff(workerDob, 'years') < 14 ) {
csvTrainingSchemaErrors.push(thisTraingRecord.dobTrainingMismatch());
}

0 comments on commit db21023

Please sign in to comment.