Skip to content

Commit

Permalink
ON-38896 # further clean up replaceCustomValues functions
Browse files Browse the repository at this point in the history
  • Loading branch information
divporter committed Mar 13, 2024
1 parent 06dfcec commit c195d48
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/replaceCustomValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ function getElementSubmissionValueByName({
}):
| { formElement: FormTypes.FormElement | undefined; unknownValue: unknown }
| undefined {
const unknownValue = submission[propertyName]
if (unknownValue === undefined || unknownValue === null) {
return undefined
}

const formElement = findFormElement(
formElements,
(element) =>
Expand All @@ -273,11 +278,6 @@ function getElementSubmissionValueByName({
element.name === propertyName,
)

const unknownValue = submission[propertyName]
if (unknownValue === undefined || unknownValue === null) {
return undefined
}

return { formElement, unknownValue }
}

Expand All @@ -289,17 +289,14 @@ function getElementSubmissionValueById({
elementId: string
formElements: FormTypes.FormElement[]
submission: SubmissionTypes.S3SubmissionData['submission']
}):
| { formElement: FormTypes.FormElement | undefined; unknownValue: unknown }
| undefined {
}): { formElement: FormTypes.FormElement; unknownValue: unknown } | undefined {
// make sure submission is an object
if (Object(submission) !== submission) {
return undefined
}

const flattenedElements = flattenFormElements(formElements)

// initialise if propertyName provided and not elementId
let unknown: unknown = undefined
let formElement: FormTypes.FormElement | undefined = undefined

Expand Down Expand Up @@ -328,7 +325,7 @@ function getElementSubmissionValueById({
}
}

if (unknown === undefined || unknown === null) {
if (unknown === undefined || unknown === null || formElement === undefined) {
return undefined
}

Expand Down

0 comments on commit c195d48

Please sign in to comment.