{"size": 1611, "ext": "js", "max_stars_repo_path": "packages/manager/apps/telecom/src/app/telecom/pack/slots/voipEcoFax/pack-voipEcoFax.controller.js", "max_stars_repo_name": "AnneSophieS/manager", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/manager/apps/telecom/src/app/telecom/pack/slots/voipEcoFax/pack-voipEcoFax.controller.js", "max_issues_repo_name": "AnneSophieS/manager", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/manager/apps/telecom/src/app/telecom/pack/slots/voipEcoFax/pack-voipEcoFax.controller.js", "max_forks_repo_name": "AnneSophieS/manager", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.9838709677, "max_line_length": 77, "alphanum_fraction": 0.6250775916}
import head from 'lodash/head';

export default class PackVoipEcoFaxCtrl {
  /* @ngInject */
  constructor(
    $q,
    $scope,
    $stateParams,
    $translate,
    OvhApiPackXdslVoipBillingAccount,
    OvhApiPackXdslVoipEcofax,
    TucToast,
    REDIRECT_URLS,
  ) {
    this.$q = $q;
    this.$scope = $scope;
    this.$stateParams = $stateParams;
    this.$translate = $translate;
    this.OvhApiPackXdslVoipBillingAccount = OvhApiPackXdslVoipBillingAccount;
    this.OvhApiPackXdslVoipEcofax = OvhApiPackXdslVoipEcofax;
    this.TucToast = TucToast;
    this.REDIRECT_URLS = REDIRECT_URLS;
  }

  $onInit() {
    this.details = this.$scope.service;
    this.packName = this.$stateParams.packName;
    this.services = [];

    this.loaders = {
      services: true,
    };

    // Get service link to this access from current Pack Xdsl
    return this.$q
      .all({
        ecofaxes: this.OvhApiPackXdslVoipEcofax.v6().query({
          packId: this.packName,
        }).$promise,
        billingAccount: this.OvhApiPackXdslVoipBillingAccount.v6().query({
          packId: this.packName,
        }).$promise,
      })
      .then(({ ecofaxes, billingAccount }) => {
        this.services = ecofaxes;
        this.billingAccount = head(billingAccount);
      })
      .catch((error) => {
        this.TucToast.error(
          this.$translate.instant('ecofax_pro_loading_error'),
        );
        return this.$q.reject(error);
      })
      .finally(() => {
        this.loaders.services = false;
      });
  }
}
angular
  .module('managerApp')
  .controller('PackVoipEcoFaxCtrl', PackVoipEcoFaxCtrl);
