This repository has been archived on 2021-09-15. You can view files and clone it, but cannot push or open issues or pull requests.
M2OLA/frontend/app/scripts/services/DataService.js

52 lines
1.5 KiB
JavaScript
Executable File

(function () {
'use strict';
angular.module('clientApp')
.factory('DataService', ['$http', '$q',
function ($http, $q) {
// ---------------------------------------------------------------------------
// PUBLIC API.
// ---------------------------------------------------------------------------
return ({
login: login,
logout: logout
});
// ---------------------------------------------------------------------------
// PUBLIC METHODS.
// ---------------------------------------------------------------------------
function login(credentials) {
// var request = $http.post(apiServer + '/api/AppUsers/login', credentials);
// return request.then(handleSuccess, handleError);
}
function logout() {
// var request = $http.post(apiServer + '/api/AppUsers/logout', {});
// return request.then(handleSuccess, handleError);
}
// ---------------------------------------------------------------------------
// PRIVATE METHODS.
// ---------------------------------------------------------------------------
function handleSuccess(response) {
return response.data;
}
function handleError(response) {
if (response.data === '' ||
!angular.isDefined(response.status) ||
response.statusText === '') {
return ($q.reject("An unknown error occurred."));
}
// Otherwise, use expected error message.
return ($q.reject('Error ' + response.status + ' (' + response.statusText + '): ' + response.data));
}
}
]);
})();