(function () { angular.module('app').factory('tenantService', ['config', '$http', '$q', tenantService]); function tenantService(config, $http, $q) { var service = { getUISettings: getUISettings, getOrgUISettings: getOrgUISettings, getTerminology: getTerminology, getOrgTerminology: getOrgTerminology }; return service; function getUISettings(hostName) { var request = $http({ method: "get", url: config.tenantUrl + 'uisettings/host/' + encodeURIComponent(hostName) }); return (request.then(handleSuccess, handleError)); } function getOrgUISettings(orgId) { var request = $http({ method: "get", url: config.tenantUrl + 'uisettings', headers: { ownerid: orgId.toUpperCase(), tenantid: orgId.toUpperCase(), } }); return (request.then(handleSuccess, handleError)); } function getTerminology(hostName) { var request = $http({ method: "get", url: config.tenantUrl + 'terminology/host/' + encodeURIComponent(hostName) }); return (request.then(handleSuccess, handleError)); } function getOrgTerminology(orgId) { var request = $http({ method: "get", url: config.tenantUrl + 'terminology', headers: { ownerid: orgId.toUpperCase(), tenantid: orgId.toUpperCase(), } }); return (request.then(handleSuccess, handleError)); } // I transform the successful response, unwrapping the application data // from the API response payload. function handleSuccess(response) { return (response.data); } function handleError(response) { // The API response from the server should be returned in a // nomralized format. However, if the request was not handled by the // server (or what not handles properly - ex. server error), then we // may have to normalize it on our end, as best we can. if ( !angular.isObject(response.data) || !response.data.message ) { return ($q.reject("An unknown error occurred.")); } // Otherwise, use expected error message. return ($q.reject(response.data.message)); } } })();