import superagent from 'superagent';

import buildAssessmentRequest from './buildAssessmentRequest';

const postAssessmentToBackend = (assessmentType, {
  nomisId,
  outcome,
  viperScore,
  questions,
  answers,
  reasons,
}, callback) => {
  const riskAssessmentRequestParams = buildAssessmentRequest(assessmentType, {
    nomisId,
    outcome,
    viperScore,
    questions,
    answers,
    reasons,
  });
  const target = `${window.location.origin}/api/assessment`;

  superagent.post(target, riskAssessmentRequestParams, (error, res) => {
    if (error) {
      if (window.appInsights) {
        window.appInsights.trackEvent('Failed to store assessment for:', { nomisId, error });
      }
      callback(null);
    } else {
      callback(res.body.data.id);
    }
  });
};

export default postAssessmentToBackend;

@@ -465,16 +465,132 @@
 ment%60;%0A%0A
+  if (window.appInsights) %7B%0A    window.appInsights.trackEvent('Posting to /api/assessment for:', %7B nomisId %7D);%0A  %7D%0A%0A
   supera

Add addtional app insights login