'use strict';

angular.module('personality.controller', [])

.controller('PersonalityController', [
'$scope', '$http', 'personalityService',
($scope, $http, personalityService) => {
  $scope.roastOptions = [
    'light',
    'medium',
    'dark'
  ];

  $scope.getData = () => {
    $http
      .put('/api/watson/' + $scope.twitter)
      .then(data => {
        $scope.array = data;

        $scope.preference = personalityService.determinePreference(data);
        $scope.curiosity = personalityService.getCuriosityPercentage(data);
        $scope.liberty = personalityService.getLibertyPercentage(data);
      })
      .catch(err => {
        console.log(err);
      })
      .finally(() => resetFeedback());
  };

  $scope.submitFeedback = actualPreference => {
    $http
      .post('/api/feedback', {
        twitter_handle: $scope.twitter,
        expected_preference: $scope.preference,
        actual_preference: actualPreference
      })
      .then(() => $scope.feedbackSubmitted = true);
  };

  $scope.showRoastFeedbackOptions = () => {
    $scope.roastFeedbackVisible = true;
  };

  function resetFeedback() {
    $scope.feedbackSubmitted = false;
    $scope.roastFeedbackVisible = false;
  }
}]);

@@ -342,17 +342,82 @@
 hen(
-data =%3E %7B
+personalityResponse =%3E %7B%0A        const profile = personalityResponse.data;
 %0A   
@@ -436,20 +436,23 @@
 array = 
-data
+profile
 ;%0A%0A     
@@ -513,20 +513,23 @@
 ference(
-data
+profile
 );%0A     
@@ -584,36 +584,39 @@
 osityPercentage(
-data
+profile
 );%0A        $scop
@@ -667,20 +667,23 @@
 centage(
-data
+profile
 );%0A     

Extract data from personality response