io-ng-util
Advanced tools
Comparing version 4.2.2 to 4.2.3
@@ -17,4 +17,4 @@ import 'rxjs/add/operator/catch'; | ||
handleError(err: any): any; | ||
makeHeaders(): RequestOptions; | ||
makeHeaders(multiPart?: boolean): RequestOptions; | ||
private extractData(res); | ||
} |
@@ -22,6 +22,21 @@ 'use strict'; | ||
HttpService.prototype.httpPost = function (url, body, flatten) { | ||
var values = !flatten | ||
? JSON.stringify(cleanObject(body)) | ||
: JSON.stringify(flattenObject(body)); | ||
return this.http.post(url, values, this.makeHeaders()) | ||
var formData; | ||
var data = !flatten | ||
? cleanObject(body) | ||
: flattenObject(body); | ||
var multiPart = false; | ||
if (data.files) { | ||
formData = new FormData(); | ||
for (var _i = 0, _a = data.files; _i < _a.length; _i++) { | ||
var file = _a[_i]; | ||
formData.append('file', file, file.name); | ||
} | ||
delete data.files; | ||
formData.append('body', JSON.stringify(data)); | ||
multiPart = true; | ||
} | ||
else { | ||
formData = JSON.stringify(data); | ||
} | ||
return this.http.post(url, formData, this.makeHeaders(multiPart)) | ||
.map(this.extractData) | ||
@@ -59,6 +74,14 @@ .catch(this.handleError); | ||
}; | ||
HttpService.prototype.makeHeaders = function () { | ||
var h = { | ||
'Content-Type': 'application/json', | ||
}; | ||
HttpService.prototype.makeHeaders = function (multiPart) { | ||
var h; | ||
if (multiPart) { | ||
h = { | ||
'Content-Type': 'multipart/form-data', | ||
}; | ||
} | ||
else { | ||
h = { | ||
'Content-Type': 'application/json', | ||
}; | ||
} | ||
if (this.env.user.token) { | ||
@@ -65,0 +88,0 @@ h.Authorization = "Bearer " + this.env.user.token; |
{ | ||
"name": "io-ng-util", | ||
"version": "4.2.2", | ||
"version": "4.2.3", | ||
"description": "Angular Base Utilities", | ||
@@ -27,4 +27,4 @@ "main": "index.js", | ||
"@types/core-js": "^0.9.43", | ||
"@types/node": "^8.0.32", | ||
"codelyzer": "^3.2.0", | ||
"@types/node": "^8.0.33", | ||
"codelyzer": "^3.2.1", | ||
"eslint": "^4.8.0", | ||
@@ -43,2 +43,2 @@ "rxjs": "^5.4.3", | ||
"dependencies": {} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60111
781