From c774efa70309f5cfe1d74f157934b6a8f0251f36 Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Tue, 9 Jul 2024 15:27:24 -0700 Subject: [PATCH] chefs data housing units fix --- app/src/controllers/submission.ts | 30 ++++--------------- app/src/services/submission.ts | 3 ++ app/src/types/ChefsSubmissionExport.ts | 1 + app/tests/unit/controllers/submission.spec.ts | 4 +++ 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/app/src/controllers/submission.ts b/app/src/controllers/submission.ts index 19199672..57a1595c 100644 --- a/app/src/controllers/submission.ts +++ b/app/src/controllers/submission.ts @@ -67,9 +67,8 @@ const controller = { : BasicResponse.NO }; - // Get greatest of multiple Units data - const unitData = [data.singleFamilyUnits, data.multiFamilyUnits, data.multiFamilyUnits1].sort(); - + // Get unit counts ready for parsing - single, multi and other + const unitData = [data.singleFamilyUnits, data.multiFamilyUnits, data.multiFamilyUnits1]; // Replace text instances with symbols const parsedUnitData = unitData.map((element) => { if (typeof element === 'string') { @@ -79,26 +78,6 @@ const controller = { } }); - const maxUnits = parsedUnitData.reduce( - (ac, value) => { - // Unit types are in the form of '1-49' or '>500' - // .match() with regex '/(\d+)(?!.*\d)/' matches the last number in a string, puts it in array. - // Get max integer from last element of array. - let upperRange: number = 0; - if (value) { - upperRange = parseInt( - value - .toString() - .match(/(\d+)(?!.*\d)/) - ?.pop() ?? '0' - ); - } - // Compare with accumulator - return upperRange > ac.upperRange ? { value: value, upperRange: upperRange } : ac; - }, - { upperRange: 0, value: '' } // Initial value - ).value; - // Attempt to create Permits defined in SHAS intake form // permitGrid/previousTrackingNumber2 is current intake version as of 2024-02-01 // dataGrid/previousTrackingNumber is previous intake version @@ -147,9 +126,12 @@ const controller = { locationPIDs: data.parcelID, latitude: data.latitude, longitude: data.longitude, + multiFamilyUnits: parsedUnitData[1], naturalDisaster: data.naturalDisasterInd ? BasicResponse.YES : BasicResponse.NO, + otherUnitsDescription: data.otherProjectType, + otherUnits: parsedUnitData[2], queuePriority: parseInt(data.queuePriority), - singleFamilyUnits: maxUnits, + singleFamilyUnits: parsedUnitData[0], hasRentalUnits: data.isRentalUnit ? camelCaseToTitleCase(deDupeUnsure(data.isRentalUnit)) : BasicResponse.UNSURE, diff --git a/app/src/services/submission.ts b/app/src/services/submission.ts index a750356f..3696b316 100644 --- a/app/src/services/submission.ts +++ b/app/src/services/submission.ts @@ -88,6 +88,9 @@ const service = { project_description: x.projectDescription, queue_priority: x.queuePriority, single_family_units: x.singleFamilyUnits, + multi_family_units: x.multiFamilyUnits, + other_units: x.otherUnits, + other_units_description: x.otherUnitsDescription, has_rental_units: x.hasRentalUnits, street_address: x.streetAddress, submitted_at: new Date(x.submittedAt ?? Date.now()), diff --git a/app/src/types/ChefsSubmissionExport.ts b/app/src/types/ChefsSubmissionExport.ts index 7fb9e049..3ca40792 100644 --- a/app/src/types/ChefsSubmissionExport.ts +++ b/app/src/types/ChefsSubmissionExport.ts @@ -34,6 +34,7 @@ export type ChefsSubmissionExport = { latitude: number; longitude: number; naturalDisasterInd: boolean; + otherProjectType: string; companyNameRegistered: string; queuePriority: string; singleFamilyUnits: string; diff --git a/app/tests/unit/controllers/submission.spec.ts b/app/tests/unit/controllers/submission.spec.ts index 7e8ca768..e2d5134e 100644 --- a/app/tests/unit/controllers/submission.spec.ts +++ b/app/tests/unit/controllers/submission.spec.ts @@ -156,6 +156,10 @@ const FORM_SUBMISSION_1: Partial