2
0

🐛 (webhook) Prioritize variables parsing over answers

This commit is contained in:
Baptiste Arnaud
2022-12-23 14:59:34 +01:00
parent 11ff7eab56
commit 64cd31cf13
2 changed files with 22 additions and 19 deletions

View File

@@ -255,6 +255,7 @@ const convertKeyValueTableToObject = (
}, {})
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const safeJsonParse = (json: string): { data: any; isJson: boolean } => {
try {
return { data: JSON.parse(json), isJson: true }

View File

@@ -190,7 +190,12 @@ export const parseAnswers =
...[...answers, ...resultVariables].reduce<{
[key: string]: string
}>((o, answerOrVariable) => {
if ('blockId' in answerOrVariable) {
const isVariable = !('blockId' in answerOrVariable)
if (isVariable) {
const variable = answerOrVariable as VariableWithValue
if (variable.value === null) return o
return { ...o, [variable.name]: variable.value }
}
const answer = answerOrVariable as Answer
const key = answer.variableId
? header.find(
@@ -202,14 +207,11 @@ export const parseAnswers =
cell.blocks?.some((block) => block.id === answer.blockId)
)?.label
if (!key) return o
if (isDefined(o[key])) return o
return {
...o,
[key]: answer.content.toString(),
}
}
const variable = answerOrVariable as VariableWithValue
if (isDefined(o[variable.name]) || variable.value === null) return o
return { ...o, [variable.name]: variable.value }
}, {}),
}
}