| 1 |
/** |
| 2 |
* Formats the site questions object into a simplified array structure |
| 3 |
* to be sent to the API. It prioritizes `answerUser`, falling back to `answerAI`. |
| 4 |
* |
| 5 |
* @param {Object} siteQA - The full siteQA object from user selection store. |
| 6 |
* @param {Array<Object>} siteQA.questions - Array of question objects. |
| 7 |
* @param {string} siteQA.questions[].question - The question text. |
| 8 |
* @param {string} [siteQA.questions[].answerUser] - User-provided answer. |
| 9 |
* @param {string} [siteQA.questions[].answerAI] - AI-generated fallback answer. |
| 10 |
* @returns {Array<{ question: string, answer: string }>} Formatted list of questions and answers. |
| 11 |
*/ |
| 12 |
export const formatSiteQuestionsForAPI = (siteQA) => { |
| 13 |
if (!Array.isArray(siteQA?.questions) || siteQA.questions.length === 0) { |
| 14 |
return []; |
| 15 |
} |
| 16 |
|
| 17 |
return siteQA.questions.map((q) => ({ |
| 18 |
id: q?.id ?? '', |
| 19 |
question: q?.question ?? '', |
| 20 |
answer: q?.answerUser ?? q?.answerAI ?? '', |
| 21 |
})); |
| 22 |
}; |
| 23 |
|