UNPKG

acha-framework

Version:

is a modular framework on both client (angular.js) and server (node.js) side, it provides security, orm, ioc, obfuscation and ...

40 lines 1.21 kB
(function ($, angular, underscore, window, document, undefined) { 'use strict'; angular.module('frontend.services').factory('apiService', [ '$http', '$q', 'Upload', function ($http, $q, Upload) { var PREFIX = '/api/v1/'; var prefix = function (url) { return PREFIX + url; }; return { PREFIX: PREFIX, get: function (path, model) { return $http.get(prefix(path || ''), model || {}); }, post: function (path, model) { return $http.post(prefix(path || ''), model || {}); }, upload: function (path, options) { Upload.upload({ url: prefix(path), data: options.data, arrayKey: '', file: options.file }).then(function (resp) { if (options.onSuccess) { options.onSuccess(resp.data); } }, options.onError, function (evt) { var percent = parseInt(100 * evt.loaded / evt.total); if (options.onProgress) { options.onProgress(percent, evt.config.data); } }); } }; } ]); }(jQuery, angular, _, window, document));