зеркало из https://github.com/microsoft/paris.git
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:
Родитель
0fa4d95f72
Коммит
7e979c3276
|
@ -2,7 +2,7 @@ import {EntityConfigBase, IEntityConfigBase} from "./entity-config.base";
|
||||||
import {ParisConfig} from "../config/paris-config";
|
import {ParisConfig} from "../config/paris-config";
|
||||||
import {DataEntityConstructor} from "./data-entity.base";
|
import {DataEntityConstructor} from "./data-entity.base";
|
||||||
import {DataQuery} from "../dataset/data-query";
|
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";
|
import {ModelBase} from "../models/model.base";
|
||||||
|
|
||||||
export class ModelEntity extends EntityConfigBase implements EntityConfig{
|
export class ModelEntity extends EntityConfigBase implements EntityConfig{
|
||||||
|
@ -44,7 +44,7 @@ export interface EntityBackendConfig{
|
||||||
getRemoveData?:(items:Array<ModelBase>) => any,
|
getRemoveData?:(items:Array<ModelBase>) => any,
|
||||||
parseDataQuery?:(dataQuery:DataQuery) => { [index:string]:any },
|
parseDataQuery?:(dataQuery:DataQuery) => { [index:string]:any },
|
||||||
parseItemQuery?:(itemId:string|number, entity?:IEntityConfigBase, config?:ParisConfig, params?:{ [index:string]:any }) => string,
|
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,
|
parseRemoveQuery?:(items:Array<ModelBase>, entity?:IEntityConfigBase, config?:ParisConfig) => string,
|
||||||
serializeItem?:(item:any, serializedItem?:any, entity?:IEntityConfigBase, config?:ParisConfig) => any,
|
serializeItem?:(item:any, serializedItem?:any, entity?:IEntityConfigBase, config?:ParisConfig) => any,
|
||||||
separateArrayParams?:boolean,
|
separateArrayParams?:boolean,
|
||||||
|
|
|
@ -53,7 +53,7 @@ export class Repository<T extends ModelBase> extends ReadonlyRepository<T> imple
|
||||||
try {
|
try {
|
||||||
let isNewItem:boolean = item.id === undefined;
|
let isNewItem:boolean = item.id === undefined;
|
||||||
let saveData: Index = this.serializeItem(item);
|
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)
|
return this.dataStore.save(endpoint, this.getSaveMethod(item), Object.assign({}, options, {data: saveData}), this.baseUrl)
|
||||||
.catch((err: AjaxError) => {
|
.catch((err: AjaxError) => {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {Observable} from "rxjs/Observable";
|
import {Observable} from "rxjs/Observable";
|
||||||
import {AjaxRequest} from "rxjs/observable/dom/AjaxObservable";
|
import {AjaxRequest} from "rxjs/observable/dom/AjaxObservable";
|
||||||
import {AjaxError, AjaxResponse} from "rxjs/Rx";
|
import {AjaxError, AjaxResponse} from "rxjs/Rx";
|
||||||
|
import * as _ from "lodash";
|
||||||
|
|
||||||
export type RequestMethod = "GET"|"POST"|"PUT"|"PATCH"|"DELETE";
|
export type RequestMethod = "GET"|"POST"|"PUT"|"PATCH"|"DELETE";
|
||||||
const DEFAULT_TIMEOUT = 60000;
|
const DEFAULT_TIMEOUT = 60000;
|
||||||
|
@ -29,12 +30,18 @@ export class Http{
|
||||||
static request(method:RequestMethod, url:string, options?:HttpOptions, httpConfig?:AjaxRequest):Observable<any> {
|
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;
|
let fullUrl:string = options && options.params ? Http.addParamsToUrl(url, options.params, options.separateArrayParams) : url;
|
||||||
|
|
||||||
if (options && options.data) {
|
let currentHttpConfig: AjaxRequest = _.clone(httpConfig);
|
||||||
httpConfig = httpConfig || {};
|
|
||||||
if (!httpConfig.headers)
|
|
||||||
httpConfig.headers = {};
|
|
||||||
|
|
||||||
(<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({
|
return Observable.ajax(Object.assign({
|
||||||
|
@ -42,7 +49,7 @@ export class Http{
|
||||||
url: fullUrl,
|
url: fullUrl,
|
||||||
body: options && options.data,
|
body: options && options.data,
|
||||||
timeout: DEFAULT_TIMEOUT
|
timeout: DEFAULT_TIMEOUT
|
||||||
}, Http.httpOptionsToRequestInit(options, httpConfig)))
|
}, Http.httpOptionsToRequestInit(options, currentHttpConfig)))
|
||||||
.catch((err: AjaxError) => {
|
.catch((err: AjaxError) => {
|
||||||
if (err.response && ~['json', 'text', 'arraybuffer', ''].indexOf(err.responseType))
|
if (err.response && ~['json', 'text', 'arraybuffer', ''].indexOf(err.responseType))
|
||||||
err.message = err.response;
|
err.message = err.response;
|
||||||
|
|
|
@ -40,7 +40,7 @@ export class Paris{
|
||||||
private _errorSubject$:Subject<EntityErrorEvent> = new Subject;
|
private _errorSubject$:Subject<EntityErrorEvent> = new Subject;
|
||||||
|
|
||||||
constructor(config?:ParisConfig){
|
constructor(config?:ParisConfig){
|
||||||
this.config = Object.assign({}, defaultConfig, config);
|
this.config = Object.freeze(Object.assign({}, defaultConfig, config));
|
||||||
this.dataStore = new DataStoreService(this.config);
|
this.dataStore = new DataStoreService(this.config);
|
||||||
|
|
||||||
this.save$ = this._saveSubject$.asObservable();
|
this.save$ = this._saveSubject$.asObservable();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "wcdportal.paris",
|
"name": "wcdportal.paris",
|
||||||
"version": "0.6.11",
|
"version": "0.6.12",
|
||||||
"description": "Library for the implementation of Domain Driven Design in Angular/TypeScript apps",
|
"description": "Library for the implementation of Domain Driven Design in Angular/TypeScript apps",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
Загрузка…
Ссылка в новой задаче