@@ -7,7 +7,12 @@ import type {
77} from 'axios'
88import type { Errors } from '..'
99import Validator from './Validator'
10- import { hasFiles , objectToFormData , removeDoubleSlash } from '../util'
10+ import {
11+ hasFiles ,
12+ objectToFormData ,
13+ removeDoubleSlash ,
14+ isObject ,
15+ } from '../util'
1116import qs , { IParseOptions } from 'qs'
1217
1318const validator = Validator
@@ -51,37 +56,46 @@ class BaseProxy {
5156 return this . submit < T > ( 'get' , id )
5257 }
5358
59+ post < T > ( payload : any ) : Promise < T >
60+ post < T > ( payload : any , config ?: AxiosRequestConfig ) : Promise < T >
5461 post < T > ( payload : any , config ?: AxiosRequestConfig ) {
5562 return this . submit < T > ( 'post' , '' , payload , config )
5663 }
5764
65+ store < T > ( payload : any ) : Promise < T >
66+ store < T > ( payload : any , config ?: AxiosRequestConfig ) : Promise < T >
5867 store < T > ( payload : any , config ?: AxiosRequestConfig ) {
5968 return this . post < T > ( payload , config )
6069 }
6170
62- create < T > ( payload : any , config ?: AxiosRequestConfig ) {
63- return this . store < T > ( payload , config )
64- }
65-
66- put < T > ( id : string | number , payload : any ) {
67- return this . submit < T > ( 'put' , `/${ id } ` , payload )
68- }
69-
70- putWithoutId < T > ( payload : any ) {
71- return this . submit < T > ( 'put' , '' , payload )
72- }
73-
74- putWithFile < T > (
71+ put < T > ( payload : any ) : Promise < T >
72+ put < T > ( id : string | number , payload : any ) : Promise < T >
73+ put < T > ( payload : any , config ?: AxiosRequestConfig ) : Promise < T >
74+ put < T > (
7575 id : string | number ,
7676 payload : any ,
7777 config ?: AxiosRequestConfig ,
78- ) {
79- payload . _method = 'put'
80- return this . submit < T > ( 'post' , `/${ id } ` , payload , config )
78+ ) : Promise < T >
79+ put < T > ( id : string | number , payload ?: any , config ?: AxiosRequestConfig ) {
80+ const parameter = id && ! isObject ( id ) ? `/${ id } ` : ''
81+ const requestType : Method = hasFiles ( payload ) ? 'post' : 'put'
82+ if ( hasFiles ( payload ) ) {
83+ Object . assign ( payload , { _method : 'put' } )
84+ }
85+ return this . submit < T > ( requestType , parameter , payload , config )
8186 }
8287
83- patch < T > ( id : string | number , payload : any ) {
84- return this . submit < T > ( 'patch' , `/${ id } ` , payload )
88+ patch < T > ( payload : any ) : Promise < T >
89+ patch < T > ( id : string | number , payload : any ) : Promise < T >
90+ patch < T > ( payload : any , config ?: AxiosRequestConfig ) : Promise < T >
91+ patch < T > (
92+ id : string | number ,
93+ payload : any ,
94+ config ?: AxiosRequestConfig ,
95+ ) : Promise < T >
96+ patch < T > ( id : string | number , payload ?: any , config ?: AxiosRequestConfig ) {
97+ const parameter = id && ! isObject ( id ) ? `/${ id } ` : ''
98+ return this . submit < T > ( 'patch' , parameter , payload , config )
8599 }
86100
87101 update < T > ( id : string | number , payload : any ) {
0 commit comments