Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ <h1 data-translate="telephony_alias_portability_order_title"></h1>
name="companyId"
class="form-control"
data-ng-model="PortabilityOrderCtrl.order.siret"
data-ng-change="PortabilityOrderCtrl.onSiretChange()"
required
/>
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ export const PORTABILITY_STEPS_STATUS = {
error: 'error',
};

export const REGEX = {
siret: /^\d{14}$/,
};

export default {
PORTABILITY_STATUS,
PORTABILITY_STEPS_GUIDE,
PORTABILITY_COUNTRY,
PORTABILITY_STEPS_STATUS,
REGEX,
};
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,16 @@ export default class TelecomTelephonyAliasPortabilitiesService {
.then(({ data }) => data)
.catch(() => null);
}

fetchEntrepriseInformations(billingAccount, serviceName, entrepriseNumber) {
return this.$http
.post(
`/telephony/${billingAccount}/service/${serviceName}/directory/fetchEntrepriseInformations`,
{
entrepriseNumber,
},
)
.then(({ data }) => data)
.catch(() => null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ import { FEATURE_TYPES } from './voip-service.constants';
export default class {
/* @ngInject */
constructor(
$http,
$q,
iceberg,
OvhApiTelephony,
TucVoipService,
TucVoipServiceAlias,
TucVoipServiceLine,
) {
this.$http = $http;
this.$q = $q;
this.iceberg = iceberg;
this.OvhApiTelephony = OvhApiTelephony;
Expand All @@ -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
Expand Down
Loading