HEX
Server: LiteSpeed
System: Linux premium267.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: predezso (1249)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //proc/self/cwd/wp-content/plugins/extendify/src/Shared/utils/format-site-questions-for-api.js
/**
 * Formats the site questions object into a simplified array structure
 * to be sent to the API. It prioritizes `answerUser`, falling back to `answerAI`.
 *
 * @param {Object} siteQA - The full siteQA object from user selection store.
 * @param {Array<Object>} siteQA.questions - Array of question objects.
 * @param {string} siteQA.questions[].question - The question text.
 * @param {string} [siteQA.questions[].answerUser] - User-provided answer.
 * @param {string} [siteQA.questions[].answerAI] - AI-generated fallback answer.
 * @returns {Array<{ question: string, answer: string }>} Formatted list of questions and answers.
 */
export const formatSiteQuestionsForAPI = (siteQA) => {
	if (!Array.isArray(siteQA?.questions) || siteQA.questions.length === 0) {
		return [];
	}

	return siteQA.questions.map((q) => ({
		id: q?.id ?? '',
		question: q?.question ?? '',
		answer: q?.answerUser ?? q?.answerAI ?? '',
	}));
};