(function () { 'use strict'; var serviceId = 'brandingDataContext'; angular.module('branding').factory(serviceId, ['$q', '$http', 'brandingConfig', '$modal', datacontext]); function datacontext($q, $http, config, $modal) { var service = { getBranding: getBranding, deleteBranding: deleteBranding, createBranding: createBranding, getTerminology: getTerminology, createTerminology: createTerminology }; return service; 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)); } // I transform the successful response, unwrapping the application data // from the API response payload. function handleSuccess(response) { return (response.data); } function getBranding(organisationId) { var request = $http({ method: "get", url: config.tenantUrl + 'uisettings', headers: { ownerId: organisationId.toUpperCase(), tenantId: organisationId.toUpperCase() } }); return (request.then(handleSuccess, handleError)); } function createBranding(branding) { var request = $http({ method: "post", url: config.tenantUrl + 'uisettings', data: Object.entries(branding).map(function (value) { return { Key: value[0], Value: value[1] } }), headers: { OwnerId: branding.organisationId.toUpperCase(), tenantId: branding.organisationId.toUpperCase() } }); return (request.then(handleSuccess, handleError)); } function deleteBranding(organisationId) { var request = $http({ method: "delete", url: config.tenantUrl + 'uisettings/all', headers: { ownerId: organisationId.toUpperCase(), tenantId: organisationId.toUpperCase() } }); return (request.then(handleSuccess, handleError)); } function getTerminology(organisationId) { var request = $http({ method: "get", url: config.tenantUrl + 'terminology', headers: { ownerId: organisationId.toUpperCase(), tenantId: organisationId.toUpperCase() } }); return (request.then(handleSuccess, handleError)); } function createTerminology(terminology, organisationId) { var request = $http({ method: "post", url: config.tenantUrl + 'terminology', data: Object.entries(terminology).map(function (value) { return { Key: value[0], Value: value[1] } }), headers: { OwnerId: organisationId.toUpperCase(), tenantId: organisationId.toUpperCase() } }); return (request.then(handleSuccess, handleError)); } } })();