PluginProbe
Extendify / 3.1.3
Extendify v3.1.3
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Shared / utils / format-site-questions-for-api.js

format-site-questions-for-api.js in Extendify 3.1.3, at src/Shared/utils/format-site-questions-for-api.js

23 lines 929 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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