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

@ -190,26 +190,28 @@ export const parseAnswers =
...[...answers, ...resultVariables].reduce<{
[key: string]: string
}>((o, answerOrVariable) => {
if ('blockId' in answerOrVariable) {
const answer = answerOrVariable as Answer
const key = answer.variableId
? header.find(
(cell) =>
answer.variableId &&
cell.variableIds?.includes(answer.variableId)
)?.label
: header.find((cell) =>
cell.blocks?.some((block) => block.id === answer.blockId)
)?.label
if (!key) return o
return {
...o,
[key]: answer.content.toString(),
}
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(
(cell) =>
answer.variableId &&
cell.variableIds?.includes(answer.variableId)
)?.label
: header.find((cell) =>
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 }
}, {}),
}
}