Skip to content

Commit

Permalink
Setting report object properties to snake case items for API
Browse files Browse the repository at this point in the history
  • Loading branch information
cosu419 committed Mar 4, 2024
1 parent 2d797ab commit 96d67cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
@@ -1,3 +1,5 @@
/* eslint-disable camelcase */

import {
fetchAndUpdateSessionExpiration as fetch,
apiRequest,
Expand Down Expand Up @@ -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,
});
}
}
Expand Down
@@ -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,
Expand All @@ -19,7 +20,7 @@ const ReportModal = ({
testReportObject,

Check warning on line 20 in src/applications/representative-search/components/results/ReportModal.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/representative-search/components/results/ReportModal.jsx:20:3:'testReportObject' is missing in props validation
}) => {
const [reportObject, setReportObject] = useState({
phone: null,
phone_number: null,
email: null,
address: null,
other: null,
Expand Down Expand Up @@ -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);
Expand All @@ -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];
}
});

Expand All @@ -103,7 +102,7 @@ const ReportModal = ({

submitRepresentativeReport(formattedReportObject);
setReportObject({
phone: null,
phone_number: null,
email: null,
address: null,
other: null,
Expand Down

0 comments on commit 96d67cc

Please sign in to comment.