Merged PR 1665741: fixed a bug where multipart forms weren't sent properly

fixed a bug where multipart forms weren't sent properly
This commit is contained in:
Omer Mizrahi 2018-04-09 15:06:53 +00:00
Родитель 0fa4d95f72
Коммит 7e979c3276
5 изменённых файлов: 18 добавлений и 11 удалений

Просмотреть файл

@ -2,7 +2,7 @@ import {EntityConfigBase, IEntityConfigBase} from "./entity-config.base";
import {ParisConfig} from "../config/paris-config";
import {DataEntityConstructor} from "./data-entity.base";
import {DataQuery} from "../dataset/data-query";
import {RequestMethod} from "../services/http.service";
import {HttpOptions, RequestMethod} from "../services/http.service";
import {ModelBase} from "../models/model.base";
export class ModelEntity extends EntityConfigBase implements EntityConfig{
@ -44,7 +44,7 @@ export interface EntityBackendConfig{
getRemoveData?:(items:Array<ModelBase>) => any,
parseDataQuery?:(dataQuery:DataQuery) => { [index:string]:any },
parseItemQuery?:(itemId:string|number, entity?:IEntityConfigBase, config?:ParisConfig, params?:{ [index:string]:any }) => string,
parseSaveQuery?:(item:any, entity?:IEntityConfigBase, config?:ParisConfig) => string,
parseSaveQuery?:(item:any, entity?:IEntityConfigBase, config?:ParisConfig, options?: HttpOptions) => string,
parseRemoveQuery?:(items:Array<ModelBase>, entity?:IEntityConfigBase, config?:ParisConfig) => string,
serializeItem?:(item:any, serializedItem?:any, entity?:IEntityConfigBase, config?:ParisConfig) => any,
separateArrayParams?:boolean,

Просмотреть файл

@ -53,7 +53,7 @@ export class Repository<T extends ModelBase> extends ReadonlyRepository<T> imple
try {
let isNewItem:boolean = item.id === undefined;
let saveData: Index = this.serializeItem(item);
let endpoint:string = this.entityBackendConfig.parseSaveQuery ? this.entityBackendConfig.parseSaveQuery(item, this.entity, this.config) : `${this.endpointName}/${item.id || ''}`;
let endpoint:string = this.entityBackendConfig.parseSaveQuery ? this.entityBackendConfig.parseSaveQuery(item, this.entity, this.config, options) : `${this.endpointName}/${item.id || ''}`;
return this.dataStore.save(endpoint, this.getSaveMethod(item), Object.assign({}, options, {data: saveData}), this.baseUrl)
.catch((err: AjaxError) => {

Просмотреть файл

@ -1,6 +1,7 @@
import {Observable} from "rxjs/Observable";
import {AjaxRequest} from "rxjs/observable/dom/AjaxObservable";
import {AjaxError, AjaxResponse} from "rxjs/Rx";
import * as _ from "lodash";
export type RequestMethod = "GET"|"POST"|"PUT"|"PATCH"|"DELETE";
const DEFAULT_TIMEOUT = 60000;
@ -29,12 +30,18 @@ export class Http{
static request(method:RequestMethod, url:string, options?:HttpOptions, httpConfig?:AjaxRequest):Observable<any> {
let fullUrl:string = options && options.params ? Http.addParamsToUrl(url, options.params, options.separateArrayParams) : url;
if (options && options.data) {
httpConfig = httpConfig || {};
if (!httpConfig.headers)
httpConfig.headers = {};
let currentHttpConfig: AjaxRequest = _.clone(httpConfig);
(<any>httpConfig.headers)["Content-Type"] = "application/json";
if (options && options.data) {
currentHttpConfig = currentHttpConfig || {};
if (!currentHttpConfig.headers)
currentHttpConfig.headers = {};
// remove content type so the browser sets it automatically. this is required for multipart forms
if (options.data instanceof FormData)
delete (<any>currentHttpConfig.headers)["Content-Type"];
else
(<any>currentHttpConfig.headers)["Content-Type"] = "application/json";
}
return Observable.ajax(Object.assign({
@ -42,7 +49,7 @@ export class Http{
url: fullUrl,
body: options && options.data,
timeout: DEFAULT_TIMEOUT
}, Http.httpOptionsToRequestInit(options, httpConfig)))
}, Http.httpOptionsToRequestInit(options, currentHttpConfig)))
.catch((err: AjaxError) => {
if (err.response && ~['json', 'text', 'arraybuffer', ''].indexOf(err.responseType))
err.message = err.response;

Просмотреть файл

@ -40,7 +40,7 @@ export class Paris{
private _errorSubject$:Subject<EntityErrorEvent> = new Subject;
constructor(config?:ParisConfig){
this.config = Object.assign({}, defaultConfig, config);
this.config = Object.freeze(Object.assign({}, defaultConfig, config));
this.dataStore = new DataStoreService(this.config);
this.save$ = this._saveSubject$.asObservable();

Просмотреть файл

@ -1,6 +1,6 @@
{
"name": "wcdportal.paris",
"version": "0.6.11",
"version": "0.6.12",
"description": "Library for the implementation of Domain Driven Design in Angular/TypeScript apps",
"repository": {
"type": "git",