| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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,
- }
|