(answers: unknown)
| 114 | } |
| 115 | |
| 116 | const normalizeAnswers = (answers: unknown): Record<string, unknown> => { |
| 117 | if (!answers || typeof answers !== 'object') return {} |
| 118 | const src = answers as Record<string, unknown> |
| 119 | const out: Record<string, unknown> = {} |
| 120 | for (const [questionId, answerObj] of Object.entries(src)) { |
| 121 | if (answerObj && typeof answerObj === 'object') { |
| 122 | const aRec = answerObj as Record<string, unknown> |
| 123 | // Find first *Answers property that contains an answers array |
| 124 | const key = Object.keys(aRec).find( |
| 125 | (k) => k.toLowerCase().endsWith('answers') && Array.isArray((aRec[k] as any)?.answers) |
| 126 | ) |
| 127 | if (key) { |
| 128 | out[questionId] = normalizeAnswerContainer(aRec[key]) |
| 129 | continue |
| 130 | } |
| 131 | } |
| 132 | out[questionId] = answerObj as unknown |
| 133 | } |
| 134 | return out |
| 135 | } |
| 136 | |
| 137 | const normalizeResponse = (r: GoogleFormsResponse): Record<string, unknown> => ({ |
| 138 | responseId: r.responseId, |
no test coverage detected