Skip to content

Commit 84c1076

Browse files
committed
fix(telecom.telephony): add auto complete enterprise name on french portability
ref: #PRDCOL-33 Signed-off-by: Guillaume Hyenne <guillaume.hyenne@ovhcloud.com>
1 parent 1dcf3f5 commit 84c1076

File tree

5 files changed

+84
-3
lines changed

5 files changed

+84
-3
lines changed

packages/manager/apps/telecom/src/app/telecom/telephony/alias/portability/order/order.controller.js

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ import uniq from 'lodash/uniq';
1212
import sortBy from 'lodash/sortBy';
1313

1414
import { SPECIAL_NUMBER_PREFIX } from '../../special/repayments/repayments.constants';
15+
import { REGEX } from '../portabilities/portabilities.constants';
1516

1617
export default /* @ngInject */ function TelecomTelephonyAliasPortabilityOrderCtrl(
1718
$q,
1819
$scope,
1920
$stateParams,
21+
$timeout,
2022
$translate,
2123
moment,
2224
tucVoipBillingAccount,
25+
tucVoipService,
2326
OvhApiMe,
2427
OvhApiOrder,
28+
TelephonyPortabilitiesService,
2529
TucBankHolidays,
2630
TucToast,
2731
canOrderSpecialPortability,
@@ -131,13 +135,21 @@ export default /* @ngInject */ function TelecomTelephonyAliasPortabilityOrderCtr
131135
};
132136

133137
// fetch list of billing accounts
134-
return tucVoipBillingAccount
135-
.fetchAll()
136-
.then((groups) => {
138+
// load one french 0033 service (needed for autocomplete the entreprise field)
139+
return $q
140+
.all({
141+
groups: tucVoipBillingAccount.fetchAll(),
142+
services: tucVoipService.fetchAllIds($stateParams.billingAccount),
143+
})
144+
.then(({ groups, services }) => {
137145
self.billingAccounts = sortBy(groups, [
138146
(group) => group.getDisplayedName(),
139147
]);
140148
self.order.billingAccount = $stateParams.billingAccount;
149+
self.serviceForFetchEntrepriseInfos =
150+
services.length > 0
151+
? services.find((number) => startsWith(number, '0033'))
152+
: null;
141153
})
142154
.catch((err) => {
143155
TucToast.error(get(err, 'data.message'));
@@ -313,6 +325,37 @@ export default /* @ngInject */ function TelecomTelephonyAliasPortabilityOrderCtr
313325
return params;
314326
};
315327

328+
self.onSiretChange = function onSiretChange() {
329+
if (
330+
self.order.siret?.match(REGEX.siret) &&
331+
self.serviceForFetchEntrepriseInfos &&
332+
self.order.country === 'france'
333+
) {
334+
// we have to poll because api call is not synchronous
335+
self
336+
.fetchEntrepriseInformations()
337+
.then((infos) => {
338+
self.order.name = infos?.informations.isValid
339+
? infos?.informations.name
340+
: '';
341+
})
342+
.catch(() => null);
343+
}
344+
};
345+
346+
self.fetchEntrepriseInformations = function fetchEntrepriseInformations() {
347+
return TelephonyPortabilitiesService.fetchEntrepriseInformations(
348+
$stateParams.billingAccount,
349+
self.serviceForFetchEntrepriseInfos,
350+
self.order.siret,
351+
).then((infos) => {
352+
if (['todo', 'doing'].includes(infos?.status)) {
353+
return $timeout(() => self.fetchEntrepriseInformations(), 500);
354+
}
355+
return infos;
356+
});
357+
};
358+
316359
self.fetchPriceAndContracts = function fetchPriceAndContracts() {
317360
self.step = 'summary';
318361
return OvhApiOrder.Telephony()

packages/manager/apps/telecom/src/app/telecom/telephony/alias/portability/order/order.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ <h1 data-translate="telephony_alias_portability_order_title"></h1>
607607
name="companyId"
608608
class="form-control"
609609
data-ng-model="PortabilityOrderCtrl.order.siret"
610+
data-ng-change="PortabilityOrderCtrl.onSiretChange()"
610611
required
611612
/>
612613
<span

packages/manager/apps/telecom/src/app/telecom/telephony/alias/portability/portabilities/portabilities.constants.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ export const PORTABILITY_STEPS_STATUS = {
2121
error: 'error',
2222
};
2323

24+
export const REGEX = {
25+
siret: /^\d{14}$/,
26+
};
27+
2428
export default {
2529
PORTABILITY_STATUS,
2630
PORTABILITY_STEPS_GUIDE,
2731
PORTABILITY_COUNTRY,
2832
PORTABILITY_STEPS_STATUS,
33+
REGEX,
2934
};

packages/manager/apps/telecom/src/app/telecom/telephony/alias/portability/portabilities/portabilities.service.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,16 @@ export default class TelecomTelephonyAliasPortabilitiesService {
8888
.then(({ data }) => data)
8989
.catch(() => null);
9090
}
91+
92+
fetchEntrepriseInformations(billingAccount, serviceName, entrepriseNumber) {
93+
return this.$http
94+
.post(
95+
`/telephony/${billingAccount}/service/${serviceName}/directory/fetchEntrepriseInformations`,
96+
{
97+
entrepriseNumber,
98+
},
99+
)
100+
.then(({ data }) => data)
101+
.catch(() => null);
102+
}
91103
}

packages/manager/modules/telecom-universe-components/src/telecom/voip/service/voip-service.service.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ import { FEATURE_TYPES } from './voip-service.constants';
2727
export default class {
2828
/* @ngInject */
2929
constructor(
30+
$http,
3031
$q,
3132
iceberg,
3233
OvhApiTelephony,
3334
TucVoipService,
3435
TucVoipServiceAlias,
3536
TucVoipServiceLine,
3637
) {
38+
this.$http = $http;
3739
this.$q = $q;
3840
this.iceberg = iceberg;
3941
this.OvhApiTelephony = OvhApiTelephony;
@@ -42,6 +44,24 @@ export default class {
4244
this.TucVoipServiceLine = TucVoipServiceLine;
4345
}
4446

47+
/**
48+
* @ngdoc method
49+
* @name managerApp.service:tucVoipService#fetchAllId
50+
* @methodOf managerApp.service:tucVoipService
51+
*
52+
* @description
53+
* Get all the service ids of one billingAccount.
54+
*
55+
* @param {String} billingAccount The billingAccount to which is attached the services.
56+
*
57+
* @return {Promise} That return an Array of TucVoipService instances.
58+
*/
59+
fetchAllIds(billingAccount) {
60+
return this.$http
61+
.get(`/telephony/${billingAccount}/service`)
62+
.then(({ data }) => data);
63+
}
64+
4565
/**
4666
* @ngdoc method
4767
* @name managerApp.service:tucVoipService#fetchAll

0 commit comments

Comments
 (0)