<commit_before>'use strict';

var _ = require('lodash');

/**@ngInject*/
function UserOrderController($scope, orders) {
  this.orders = this.getOrderStatus(orders);
}

function _reduceItemStatus(status, order_item) {
  var itemStatus = null;
  var provision_status_map = { ok: 0, pending: 1, unknown: 2, warning: 3, critical: 4, retired: 5 };
  // undefined status and 'unknown' statuses are set to 'warning' for order status
  if ((typeof order_item.provision_status === "undefined") || (order_item.provision_status === "unknown")) {
    itemStatus = "warning";
  } else {
    itemStatus = order_item.provision_status;
  }
  // Compare levels of the statuses - the higher status should represent the status of the order (except retired)
  if ((provision_status_map[itemStatus] > provision_status_map[status]) && (itemStatus !== "retired")) {
    return itemStatus;
  } else {
    // Return existing status
    return status;
  }
}

UserOrderController.prototype.getOrders = function() {
  return this.orders;
};

UserOrderController.prototype.getOrderStatus = function(orders) {
  _.each(orders, function(order)
  {
    if (_.every(order.order_items, function(order_item){return order_item.provision_status === "retired";})) {
      order.provision_status = "retired";
    }
    else {
      order.provision_status = _.reduce(order.order_items, _reduceItemStatus, "ok");
    }
  });
  return orders;
};

UserOrderController.resolve = {
  /**@ngInject*/
  orders: function(UserOrders, currentUser) {
    return UserOrders.query({staff_id: currentUser.id}).$promise;
  }
};
<commit_msg>Adjusted the _.every() statement to use _.isMatch() syntax<commit_after>'use strict';

var _ = require('lodash');

/**@ngInject*/
function UserOrderController($scope, orders) {
  this.orders = this.getOrderStatus(orders);
}

function _reduceItemStatus(status, order_item) {
  var itemStatus = null;
  var provision_status_map = { ok: 0, pending: 1, unknown: 2, warning: 3, critical: 4, retired: 5 };
  // undefined status and 'unknown' statuses are set to 'warning' for order status
  if ((typeof order_item.provision_status === "undefined") || (order_item.provision_status === "unknown")) {
    itemStatus = "warning";
  } else {
    itemStatus = order_item.provision_status;
  }
  // Compare levels of the statuses - the higher status should represent the status of the order (except retired)
  if ((provision_status_map[itemStatus] > provision_status_map[status]) && (itemStatus !== "retired")) {
    return itemStatus;
  } else {
    // Return existing status
    return status;
  }
}

UserOrderController.prototype.getOrders = function() {
  return this.orders;
};

UserOrderController.prototype.getOrderStatus = function(orders) {
  _.each(orders, function(order)
  {
    if (_.every(order.order_items, {provision_status: 'retired'})) {
      order.provision_status = "retired";
    }
    else {
      order.provision_status = _.reduce(order.order_items, _reduceItemStatus, "ok");
    }
  });
  return orders;
};

UserOrderController.resolve = {
  /**@ngInject*/
  orders: function(UserOrders, currentUser) {
    return UserOrders.query({staff_id: currentUser.id}).$promise;
  }
};

{'fraction_non_alphanumeric': 0.1342578001890955, 'fraction_numerical': 0.003781909864481563, 'mean_word_length': 4.3524451939291735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7145308', 'n_tokens_mistral': 990, 'n_tokens_neox': 977, 'n_words': 232}