From 10618560da9778417bea21654c0fb581ee4bcbfa Mon Sep 17 00:00:00 2001 From: Guillaume Hyenne Date: Fri, 24 Oct 2025 17:13:55 +0200 Subject: [PATCH] fix(telecom.telephony): add auto complete enterprise name on french portability ref: #PRDCOL-33 Signed-off-by: Guillaume Hyenne --- .../portability/order/order.controller.js | 49 +++++++++++++++++-- .../alias/portability/order/order.html | 1 + .../portabilities/portabilities.constants.js | 5 ++ .../portabilities/portabilities.service.js | 12 +++++ .../voip/service/voip-service.service.js | 20 ++++++++ 5 files changed, 84 insertions(+), 3 deletions(-) diff --git a/packages/manager/apps/telecom/src/app/telecom/telephony/alias/portability/order/order.controller.js b/packages/manager/apps/telecom/src/app/telecom/telephony/alias/portability/order/order.controller.js index 21d1f47eca12..5d4d7bb75ae5 100644 --- a/packages/manager/apps/telecom/src/app/telecom/telephony/alias/portability/order/order.controller.js +++ b/packages/manager/apps/telecom/src/app/telecom/telephony/alias/portability/order/order.controller.js @@ -12,16 +12,20 @@ import uniq from 'lodash/uniq'; import sortBy from 'lodash/sortBy'; import { SPECIAL_NUMBER_PREFIX } from '../../special/repayments/repayments.constants'; +import { REGEX } from '../portabilities/portabilities.constants'; export default /* @ngInject */ function TelecomTelephonyAliasPortabilityOrderCtrl( $q, $scope, $stateParams, + $timeout, $translate, moment, tucVoipBillingAccount, + tucVoipService, OvhApiMe, OvhApiOrder, + TelephonyPortabilitiesService, TucBankHolidays, TucToast, canOrderSpecialPortability, @@ -131,13 +135,21 @@ export default /* @ngInject */ function TelecomTelephonyAliasPortabilityOrderCtr }; // fetch list of billing accounts - return tucVoipBillingAccount - .fetchAll() - .then((groups) => { + // load one french 0033 service (needed for autocomplete the entreprise field) + return $q + .all({ + groups: tucVoipBillingAccount.fetchAll(), + services: tucVoipService.fetchAllIds($stateParams.billingAccount), + }) + .then(({ groups, services }) => { self.billingAccounts = sortBy(groups, [ (group) => group.getDisplayedName(), ]); self.order.billingAccount = $stateParams.billingAccount; + self.serviceForFetchEntrepriseInfos = + services.length > 0 + ? services.find((number) => startsWith(number, '0033')) + : null; }) .catch((err) => { TucToast.error(get(err, 'data.message')); @@ -313,6 +325,37 @@ export default /* @ngInject */ function TelecomTelephonyAliasPortabilityOrderCtr return params; }; + self.onSiretChange = function onSiretChange() { + if ( + self.order.siret?.match(REGEX.siret) && + self.serviceForFetchEntrepriseInfos && + self.order.country === 'france' + ) { + // we have to poll because api call is not synchronous + self + .fetchEntrepriseInformations() + .then((infos) => { + self.order.name = infos?.informations.isValid + ? infos?.informations.name + : ''; + }) + .catch(() => null); + } + }; + + self.fetchEntrepriseInformations = function fetchEntrepriseInformations() { + return TelephonyPortabilitiesService.fetchEntrepriseInformations( + $stateParams.billingAccount, + self.serviceForFetchEntrepriseInfos, + self.order.siret, + ).then((infos) => { + if (['todo', 'doing'].includes(infos?.status)) { + return $timeout(() => self.fetchEntrepriseInformations(), 500); + } + return infos; + }); + }; + self.fetchPriceAndContracts = function fetchPriceAndContracts() { self.step = 'summary'; return OvhApiOrder.Telephony() diff --git a/packages/manager/apps/telecom/src/app/telecom/telephony/alias/portability/order/order.html b/packages/manager/apps/telecom/src/app/telecom/telephony/alias/portability/order/order.html index 2c383271f60d..d83bf456752e 100644 --- a/packages/manager/apps/telecom/src/app/telecom/telephony/alias/portability/order/order.html +++ b/packages/manager/apps/telecom/src/app/telecom/telephony/alias/portability/order/order.html @@ -607,6 +607,7 @@

name="companyId" class="form-control" data-ng-model="PortabilityOrderCtrl.order.siret" + data-ng-change="PortabilityOrderCtrl.onSiretChange()" required /> data) .catch(() => null); } + + fetchEntrepriseInformations(billingAccount, serviceName, entrepriseNumber) { + return this.$http + .post( + `/telephony/${billingAccount}/service/${serviceName}/directory/fetchEntrepriseInformations`, + { + entrepriseNumber, + }, + ) + .then(({ data }) => data) + .catch(() => null); + } } diff --git a/packages/manager/modules/telecom-universe-components/src/telecom/voip/service/voip-service.service.js b/packages/manager/modules/telecom-universe-components/src/telecom/voip/service/voip-service.service.js index 4d22c596ad7d..83b03327c3fd 100644 --- a/packages/manager/modules/telecom-universe-components/src/telecom/voip/service/voip-service.service.js +++ b/packages/manager/modules/telecom-universe-components/src/telecom/voip/service/voip-service.service.js @@ -27,6 +27,7 @@ import { FEATURE_TYPES } from './voip-service.constants'; export default class { /* @ngInject */ constructor( + $http, $q, iceberg, OvhApiTelephony, @@ -34,6 +35,7 @@ export default class { TucVoipServiceAlias, TucVoipServiceLine, ) { + this.$http = $http; this.$q = $q; this.iceberg = iceberg; this.OvhApiTelephony = OvhApiTelephony; @@ -42,6 +44,24 @@ export default class { this.TucVoipServiceLine = TucVoipServiceLine; } + /** + * @ngdoc method + * @name managerApp.service:tucVoipService#fetchAllId + * @methodOf managerApp.service:tucVoipService + * + * @description + * Get all the service ids of one billingAccount. + * + * @param {String} billingAccount The billingAccount to which is attached the services. + * + * @return {Promise} That return an Array of TucVoipService instances. + */ + fetchAllIds(billingAccount) { + return this.$http + .get(`/telephony/${billingAccount}/service`) + .then(({ data }) => data); + } + /** * @ngdoc method * @name managerApp.service:tucVoipService#fetchAll