import { db } from '../utils/db.js' /** * Get Survey for first time profile creation from the database and * create a class from the data and * validate the incoming against the schema * @param {number} profileId * @returns {array} instantiated Profile objects (see: /entites/profile) */ const fetchQuestions = async () => { const questions = await db.get(`/survey/questions`) // Add responses to match the format from the survery factory return questions.map(q => { q.responses = !q.responses ? [] : q.responses return q }) } const updateSurveyByProfileId = async (surveyResponses, profileId) => { surveyResponses.forEach(responseKeyIdwithVal => { const keyId = responseKeyIdwithVal.response_key_id const val = responseKeyIdwithVal.val // PATCH db.patch(`/profile/${profileId}/update/${keyId}`, [ { response_id: 2, profile_id: profileId, response_key_id: keyId, val: val, }, ]) }) } // const updateSurveyByProfileId = async (surveyResponses, profileId) => { // surveyResponses.forEach(responseKeyIdwithVal => { // const keyId = responseKeyIdwithVal.response_key_id // const val = responseKeyIdwithVal.val // // PATCH // db.patch(`/profile/${profileId}/update/${keyId}`, [ // { // response_id: 2, // profile_id: profileId, // response_key_id: keyId, // val: val, // }, // ]) // }) // } const scoreSurveyByProfileId = async (profileId, maxDistance = 99) => { const scoreSurvey = await db.get( `/profile/${profileId}/score?max_distance=${maxDistance}`, ) return scoreSurvey } const fetchResponsesByProfileId = async profileId => { return await db.get(`/profile/${profileId}/responses`) } export { fetchQuestions, updateSurveyByProfileId, scoreSurveyByProfileId, fetchResponsesByProfileId, }