From 96d67cca50bfffc63a16f2c2d18f8d7797386820 Mon Sep 17 00:00:00 2001 From: Colin O'Sullivan <143013011+cosu419@users.noreply.github.com> Date: Mon, 4 Mar 2024 10:46:04 -0500 Subject: [PATCH] Setting report object properties to snake case items for API --- .../api/RepresentativeFinderApi.js | 14 ++++++++----- .../components/results/ReportModal.jsx | 21 +++++++++---------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/applications/representative-search/api/RepresentativeFinderApi.js b/src/applications/representative-search/api/RepresentativeFinderApi.js index b9bcc1da8a59..1a1664a2e20a 100644 --- a/src/applications/representative-search/api/RepresentativeFinderApi.js +++ b/src/applications/representative-search/api/RepresentativeFinderApi.js @@ -1,3 +1,5 @@ +/* eslint-disable camelcase */ + import { fetchAndUpdateSessionExpiration as fetch, apiRequest, @@ -64,17 +66,19 @@ class RepresentativeFinderApi { static reportResult(newReport) { const reportRequestBody = { - representativeId: newReport.representativeId, + representative_id: newReport.representative_id, flags: [], }; const startTime = new Date().getTime(); - for (const [flagType, flaggedValue] of Object.entries(newReport.reports)) { - if (flaggedValue !== null) { + for (const [flag_type, flagged_value] of Object.entries( + newReport.reports, + )) { + if (flagged_value !== null) { reportRequestBody.flags.push({ - flagType, - flaggedValue, + flag_type, + flagged_value, }); } } diff --git a/src/applications/representative-search/components/results/ReportModal.jsx b/src/applications/representative-search/components/results/ReportModal.jsx index 7f91b80c07b7..b9a6cf14775a 100644 --- a/src/applications/representative-search/components/results/ReportModal.jsx +++ b/src/applications/representative-search/components/results/ReportModal.jsx @@ -1,10 +1,11 @@ +/* eslint-disable camelcase */ + import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { VaModal, VaCheckboxGroup, } from '@department-of-veterans-affairs/component-library/dist/react-bindings'; -import { snakeCase } from 'lodash'; const ReportModal = ({ representativeName, @@ -19,7 +20,7 @@ const ReportModal = ({ testReportObject, }) => { const [reportObject, setReportObject] = useState({ - phone: null, + phone_number: null, email: null, address: null, other: null, @@ -64,7 +65,7 @@ const ReportModal = ({ newState.email = checked ? email : null; break; case '3': - newState.phone = checked ? phone : null; + newState.phone_number = checked ? phone : null; break; case '4': setOtherIsBlankError(false); @@ -78,17 +79,15 @@ const ReportModal = ({ }; const onSubmitModal = () => { - const formattedReportObject = { representativeId, reports: {} }; + const formattedReportObject = { + representative_id: representativeId, + reports: {}, + }; // push non-null items to reports object Object.keys(reportObject).forEach(prop => { if (reportObject[prop] !== null) { - if (prop === 'phone') { - formattedReportObject.reports[snakeCase('phoneNumber')] = - reportObject.phone; - } else { - formattedReportObject.reports[prop] = reportObject[prop]; - } + formattedReportObject.reports[prop] = reportObject[prop]; } }); @@ -103,7 +102,7 @@ const ReportModal = ({ submitRepresentativeReport(formattedReportObject); setReportObject({ - phone: null, + phone_number: null, email: null, address: null, other: null,