refactor(newappeal): extract payload cleanup helpers (Slice 2a)
- extracted boolean normalization - extracted null key removal - extracted internal key stripping - no behaviour change
This commit is contained in:
@@ -6,6 +6,11 @@ import { connect } from "react-redux";
|
||||
import { formValueSelector, reduxForm } from "redux-form";
|
||||
import { uploadFiles } from "../../actions/services/documentService";
|
||||
import { sendEmail } from "../../actions/services/notifyService";
|
||||
import {
|
||||
normalizeYesNoBooleans,
|
||||
removeNullKeys,
|
||||
stripInternalKeys
|
||||
} from "../../lib/newappeal/payloadCleanup";
|
||||
import {
|
||||
setCurrentSection,
|
||||
setDocumentsList,
|
||||
@@ -218,19 +223,9 @@ let BuildSection = (props) => {
|
||||
"/incidents(" + incidentId + ")"
|
||||
});
|
||||
|
||||
updateBody = JSON.stringify(updateBody);
|
||||
updateBody = updateBody.replace(/:"Yes"/gm, `:true`);
|
||||
updateBody = updateBody.replace(/:"No"/gm, `:false`);
|
||||
updateBody = JSON.parse(updateBody);
|
||||
|
||||
Object.keys(updateBody).forEach((key) => {
|
||||
if (updateBody[key] === null) {
|
||||
delete updateBody[key];
|
||||
}
|
||||
if (key.indexOf("_") == 0) {
|
||||
delete updateBody[key];
|
||||
}
|
||||
});
|
||||
updateBody = normalizeYesNoBooleans(updateBody);
|
||||
updateBody = removeNullKeys(updateBody);
|
||||
updateBody = stripInternalKeys(updateBody);
|
||||
|
||||
//console.log(updateBody);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { useEffect } from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { formValueSelector } from "redux-form";
|
||||
import { sendEmail } from "../../actions/services/notifyService";
|
||||
import { normalizeYesNoBooleans } from "../../lib/newappeal/payloadCleanup";
|
||||
import { setCurrentSection } from "../../store/appealType/action";
|
||||
import { getFormCollectionByID } from "../utils";
|
||||
|
||||
@@ -31,10 +32,7 @@ let CompleteAppeal = (props) => {
|
||||
"/incidents(" + incidentId + ")"
|
||||
});
|
||||
|
||||
updateBody = JSON.stringify(updateBody);
|
||||
updateBody = updateBody.replace(/:"Yes"/gm, `:true`);
|
||||
updateBody = updateBody.replace(/:"No"/gm, `:false`);
|
||||
updateBody = JSON.parse(updateBody);
|
||||
updateBody = normalizeYesNoBooleans(updateBody);
|
||||
|
||||
let updateFormCollection = appTypeCollection.LogicalCollectionName;
|
||||
let primaryAttribute = appTypeCollection.PrimaryIdAttribute;
|
||||
|
||||
Reference in New Issue
Block a user