This repository has been archived by the owner on Dec 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(voip line phone): add call to APIv7 for fetching all phones
- Loading branch information
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...t/components/telecom/voip/feature/line/line/phone/voip-feature-line-line-phone.factory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* @ngdoc object | ||
* @name managerApp.object:VoipLinePhone | ||
* | ||
* @description | ||
* <p>Factory that describes a phone of a service with sip or mgcp featureType with attributes returned by `/telephony/{billingAccount}/line/{serviceName}/phone` API.</p> | ||
* | ||
* @constructor | ||
* @param {Object} options Options required for creating a new instance of VoipLinePhone (see {@link https://eu.api.ovh.com/console/#/telephony/%7BbillingAccount%7D/line/%7BserviceName%7D/phone#GET `telephony.Phone` enum} | ||
* for available options properties). | ||
* | ||
* Note that `billingAccount` and `serviceName` options are mandatory. | ||
*/ | ||
angular.module("managerApp").factory("VoipLinePhone", function () { | ||
"use strict"; | ||
|
||
const mandatoryOptions = ["billingAccount", "serviceName"]; | ||
|
||
class VoipLinePhone { | ||
constructor (options = {}) { | ||
// check for mandatory options | ||
mandatoryOptions.forEach((option) => { | ||
if (!options[option]) { | ||
throw new Error(`${option} option must be specified when creating a new VoipLinePhone`); | ||
} | ||
}); | ||
|
||
// populate object attributes | ||
// mandatory attribute | ||
this.billingAccount = options.billingAccount; | ||
this.serviceName = options.serviceName; | ||
|
||
// populate other object attributes | ||
this.setOptions(options); | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @name managerApp.object:VoipLinePhone#setOptions | ||
* @propertyOf managerApp.object:VoipLinePhone | ||
* | ||
* @description | ||
* Set the options from `telephony.Phone` enum. This is called by default by the constructor. | ||
* | ||
* @param {Object} options Optional options for creating a new instance of VoipLinePhone. | ||
* | ||
* @return {VoipLinePhone} The `VoipLinePhone` instance with options setted. | ||
*/ | ||
setOptions (phoneOptions) { | ||
this.protocol = phoneOptions.protocol; | ||
this.macAddress = phoneOptions.macAddress; | ||
this.maxline = phoneOptions.maxline; | ||
this.mgcpIpRestriction = phoneOptions.mgcpIpRestriction; | ||
this.description = phoneOptions.description; | ||
this.phoneConfiguration = phoneOptions.phoneConfiguration; | ||
} | ||
} | ||
|
||
return VoipLinePhone; | ||
|
||
}); |
48 changes: 48 additions & 0 deletions
48
...t/components/telecom/voip/feature/line/line/phone/voip-feature-line-line-phone.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @ngdoc service | ||
* @name managerApp.service:voipLinePhone | ||
* | ||
* @description | ||
* <p>Service that manage phone linked to sip and mgcp features of services with serviceType line.</p> | ||
* <p>This service will manage API calls to `/telephony/{billingAccount}/line/{serviceName}/phone`</p> | ||
*/ | ||
angular.module("managerApp").service("voipLinePhone", class { | ||
|
||
constructor (VoipLinePhone, voipService, OvhApiTelephony) { | ||
this.VoipLinePhone = VoipLinePhone; | ||
this.voipService = voipService; | ||
this.OvhApiTelephony = OvhApiTelephony; | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @name managerApp.service:voipLinePhone#fetchAll | ||
* @methodOf managerApp.service:voipLinePhone | ||
* | ||
* @description | ||
* Fetch all phone of all services of serviceType line with featureType sip or mgcp from any billingAccount. This use APIv7 with wildcard and aggregation to achieve it. | ||
* | ||
* @return {Promise} That return an array of VoipLinePhone instances. | ||
*/ | ||
fetchAll () { | ||
return this.OvhApiTelephony.Line().Phone().Erika().query().aggregate("billingAccount").aggregate("serviceName").expand().execute().$promise.then((results) => { | ||
let phoneList = []; | ||
|
||
results.forEach((result) => { | ||
// first retrieve billingAccount and serviceName from path | ||
let splittedPath = result.path.split("/"); | ||
|
||
// extend phone options | ||
let phoneOptions = angular.extend(result.value, { | ||
billingAccount: splittedPath[2], | ||
serviceName: splittedPath[4] | ||
}); | ||
|
||
phoneList.push(new this.VoipLinePhone(phoneOptions)); | ||
}); | ||
|
||
return phoneList; | ||
}); | ||
} | ||
|
||
}); |