Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright 2016 Thomson Reuters/ONESOURCE. All rights reserved.
- */
- (function () {
- 'use strict';
- angular
- .module('indirect.determination')
- .factory('apiFactory', ApiFactory);
- ApiFactory.$inject = ['$http', '$log', 'lonestarUtilityFactory', 'indirectEnumeration'];
- /**
- * A list of service methods that connect to the RESTful api. <p/>
- *
- * @param $http The angular $http service.
- * @param $log The angular $log service.
- * @param lonestarUtilityFactory A reference to the utilityFactory service in determination.
- * @param indirectEnumeration A reference to the indirectEnumeration service (constants).
- *
- * @returns object A single object of service methods for connecting to a RESTful api.
- */
- function ApiFactory($http, $log, lonestarUtilityFactory, indirectEnumeration) {
- var service = {};
- service.config = {
- 'host': '',
- '$lonestarUser': null,
- '$lonestarConfig': null
- };
- /**
- * Gets the base Url for the RESTful API for both LS2 and standalone. <p/>
- *
- * @returns string The base Url host for the API to both LS2 and standalone.
- */
- service.getHost = function getHost() {
- if (service.config.host !== '') {
- return service.config.host;
- }
- try {
- if (lonestarUtilityFactory.isInLoneStar()) {
- service.config.$lonestarUser = lonestarUtilityFactory.getUserInfo();
- service.config.$lonestarConfig = lonestarUtilityFactory.getLoneStarConfig();
- if (lonestarUtilityFactory.hasLoneStarConfig(service.config.$lonestarConfig)) {
- var serviceSuffix = indirectEnumeration.ZuulServiceId + '/' + indirectEnumeration.ApiVersion;
- service.config.host = service.config.$lonestarConfig.getBaseUrl() + serviceSuffix;
- }
- }
- } catch (err) {
- $log.debug(err);
- }
- return service.config.host;
- };
- /**
- * This method fetches a list of all companies from the backend. <p/>
- *
- * @return {*} Returns a promise with the list of all companies.
- */
- service.getListOfCompanies = function getListOfCompanies() {
- return $http.get(service.getHost() + '/companies');
- };
- /**
- * Gets the registration info for a user by userId. <p/>
- *
- * @param userId The user identifier.
- *
- * @returns {*} Returns a promise of registration information.
- */
- service.getRegistrationByUserId = function getRegistrationByUserId(userId) {
- return $http({
- method: 'GET',
- url: service.getHost() + '/getRegistrationByUserId',
- data : {
- merchantId: userId
- }
- });
- };
- return service;
- }
- }());
Add Comment
Please, Sign In to add comment