Fixed most of the dependencies by unit testing.

Refactored TransactionService and StorageService.
This commit is contained in:
Gunther Brunner
2014-08-22 15:32:09 +09:00
parent e27e17d699
commit aad3db8828
16 changed files with 32 additions and 18 deletions

View File

@@ -0,0 +1,48 @@
var Promise = require('bluebird')
module.exports = function StorageServiceFactory($http, $upload) {
var service = {}
service.storeUrl = function(type, url) {
return $http({
url: '/api/v1/s/' + type + '/download'
, method: 'POST'
, data: {
url: url
}
})
}
service.storeFile = function(type, files, options) {
var resolver = Promise.defer()
var input = options.filter ? files.filter(options.filter) : files
if (input.length) {
$upload.upload({
url: '/api/v1/s/' + type
, method: 'POST'
, file: input
})
.then(
function(value) {
resolver.resolve(value)
}
, function(err) {
resolver.reject(err)
}
, function(progressEvent) {
resolver.progress(progressEvent)
}
)
}
else {
var err = new Error('No input files')
err.code = 'no_input_files'
resolver.reject(err)
}
return resolver.promise
}
return service
}