🐛 (webhook) Prioritize variables parsing over answers
This commit is contained in:
@@ -255,6 +255,7 @@ const convertKeyValueTableToObject = (
|
|||||||
}, {})
|
}, {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const safeJsonParse = (json: string): { data: any; isJson: boolean } => {
|
const safeJsonParse = (json: string): { data: any; isJson: boolean } => {
|
||||||
try {
|
try {
|
||||||
return { data: JSON.parse(json), isJson: true }
|
return { data: JSON.parse(json), isJson: true }
|
||||||
|
|||||||
@@ -190,26 +190,28 @@ export const parseAnswers =
|
|||||||
...[...answers, ...resultVariables].reduce<{
|
...[...answers, ...resultVariables].reduce<{
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
}>((o, answerOrVariable) => {
|
}>((o, answerOrVariable) => {
|
||||||
if ('blockId' in answerOrVariable) {
|
const isVariable = !('blockId' in answerOrVariable)
|
||||||
const answer = answerOrVariable as Answer
|
if (isVariable) {
|
||||||
const key = answer.variableId
|
const variable = answerOrVariable as VariableWithValue
|
||||||
? header.find(
|
if (variable.value === null) return o
|
||||||
(cell) =>
|
return { ...o, [variable.name]: variable.value }
|
||||||
answer.variableId &&
|
}
|
||||||
cell.variableIds?.includes(answer.variableId)
|
const answer = answerOrVariable as Answer
|
||||||
)?.label
|
const key = answer.variableId
|
||||||
: header.find((cell) =>
|
? header.find(
|
||||||
cell.blocks?.some((block) => block.id === answer.blockId)
|
(cell) =>
|
||||||
)?.label
|
answer.variableId &&
|
||||||
if (!key) return o
|
cell.variableIds?.includes(answer.variableId)
|
||||||
return {
|
)?.label
|
||||||
...o,
|
: header.find((cell) =>
|
||||||
[key]: answer.content.toString(),
|
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 }
|
|
||||||
}, {}),
|
}, {}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user