Skip to content

Commit 0a374cc

Browse files
authored
Merge pull request #382 from chantouchsek/bugfix/381-put-method
Bugfix/381 put method
2 parents c3b501e + 3cf6170 commit 0a374cc

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

src/core/BaseService.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ class BaseService {
7373
return this.post<T>(payload, config)
7474
}
7575

76-
put<T>(payload: any): Promise<T>
77-
put<T>(id: string | number, payload: any): Promise<T>
7876
put<T>(payload: any, config?: AxiosRequestConfig): Promise<T>
7977
put<T>(
8078
id: string | number,
@@ -83,15 +81,14 @@ class BaseService {
8381
): Promise<T>
8482
put<T>(id: string | number, payload?: any, config?: AxiosRequestConfig) {
8583
const parameter = id && !isObject(id) ? `/${id}` : ''
86-
const requestType: Method = hasFiles(payload) ? 'post' : 'put'
87-
if (hasFiles(payload)) {
88-
Object.assign(payload, { _method: 'put' })
84+
const body = isObject(id) ? id : payload
85+
const requestType: Method = hasFiles(body) ? 'post' : 'put'
86+
if (hasFiles(body)) {
87+
Object.assign(body, { _method: 'put' })
8988
}
90-
return this.submit<T>(requestType, parameter, payload, config)
89+
return this.submit<T>(requestType, parameter, body, config)
9190
}
9291

93-
patch<T>(payload: any): Promise<T>
94-
patch<T>(id: string | number, payload: any): Promise<T>
9592
patch<T>(payload: any, config?: AxiosRequestConfig): Promise<T>
9693
patch<T>(
9794
id: string | number,
@@ -100,7 +97,8 @@ class BaseService {
10097
): Promise<T>
10198
patch<T>(id: string | number, payload?: any, config?: AxiosRequestConfig) {
10299
const parameter = id && !isObject(id) ? `/${id}` : ''
103-
return this.submit<T>('patch', parameter, payload, config)
100+
const body = isObject(id) ? id : payload
101+
return this.submit<T>('patch', parameter, body, config)
104102
}
105103

106104
update<T>(id: string | number, payload: any) {
@@ -115,19 +113,6 @@ class BaseService {
115113
return this.delete<T>(id)
116114
}
117115

118-
submit<T = any>(requestType: Method): Promise<T>
119-
submit<T = any>(requestType: Method, parameter?: string | number): Promise<T>
120-
submit<T = any>(
121-
requestType: Method,
122-
parameter?: string | number,
123-
form?: T,
124-
): Promise<T>
125-
submit<T = any>(
126-
requestType: Method,
127-
parameter?: string | number,
128-
form?: T,
129-
config?: AxiosRequestConfig,
130-
): Promise<T>
131116
submit<T = any>(
132117
requestType: Method,
133118
parameter?: string | number,

0 commit comments

Comments
 (0)