Skip to content

Commit

Permalink
chefs data housing units fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjaytkbabu committed Jul 10, 2024
1 parent 96964ad commit c774efa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
30 changes: 6 additions & 24 deletions app/src/controllers/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions app/src/services/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
1 change: 1 addition & 0 deletions app/src/types/ChefsSubmissionExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type ChefsSubmissionExport = {
latitude: number;
longitude: number;
naturalDisasterInd: boolean;
otherProjectType: string;
companyNameRegistered: string;
queuePriority: string;
singleFamilyUnits: string;
Expand Down
4 changes: 4 additions & 0 deletions app/tests/unit/controllers/submission.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ const FORM_SUBMISSION_1: Partial<Submission & { activityId: string; formId: stri
latitude: -48,
longitude: 160,
naturalDisaster: BasicResponse.YES,
multiFamilyUnits: '',
otherUnits: '',
otherUnitsDescription: undefined,
projectDescription: undefined,
projectName: 'PROJ',
queuePriority: 3,
singleFamilyUnits: '1-49',
Expand Down

0 comments on commit c774efa

Please sign in to comment.