1- import type {
2- AxiosError ,
3- AxiosInstance ,
4- AxiosResponse ,
5- Method ,
6- AxiosRequestConfig ,
7- } from 'axios'
1+ import type { AxiosError , AxiosInstance , AxiosResponse , Method , AxiosRequestConfig } from 'axios'
82import type { Errors } from '..'
93import Validator from './Validator'
104import { hasFiles , objectToFormData , removeDoubleSlash } from '../util'
@@ -48,23 +42,23 @@ class BaseService {
4842 return BaseService . $parsedQs
4943 }
5044
51- all < T > ( ) {
45+ all < T = any > ( ) {
5246 return this . submit < T > ( 'get' )
5347 }
5448
55- find < T > ( id : number | string ) {
49+ find < T = any > ( id : number | string ) {
5650 return this . submit < T > ( 'get' , id )
5751 }
5852
59- post < T > ( payload : any , config ?: AxiosRequestConfig ) {
53+ post < T = any > ( payload : any , config ?: AxiosRequestConfig ) {
6054 return this . submit < T > ( 'post' , '' , payload , config )
6155 }
6256
63- store < T > ( payload : any , config ?: AxiosRequestConfig ) {
57+ store < T = any > ( payload : any , config ?: AxiosRequestConfig ) {
6458 return this . post < T > ( payload , config )
6559 }
6660
67- put < T > ( id : any , payload ?: any , config ?: AxiosRequestConfig ) {
61+ put < T = any > ( id : any , payload ?: any , config ?: AxiosRequestConfig ) {
6862 const parameter = id && ! isObject ( id ) ? `/${ id } ` : ''
6963 const body = isObject ( id ) ? id : payload
7064 const requestType : Method = hasFiles ( body ) ? 'post' : 'put'
@@ -74,43 +68,36 @@ class BaseService {
7468 return this . submit < T > ( requestType , parameter , body , config )
7569 }
7670
77- patch < T > ( id : any , payload ?: any , config ?: AxiosRequestConfig ) {
71+ patch < T = any > ( id : any , payload ?: any , config ?: AxiosRequestConfig ) {
7872 const parameter = id && ! isObject ( id ) ? `/${ id } ` : ''
7973 const body = isObject ( id ) ? id : payload
8074 return this . submit < T > ( 'patch' , parameter , body , config )
8175 }
8276
83- update < T > ( id : string | number , payload : any ) {
77+ update < T = any > ( id : string | number , payload : any ) {
8478 return this . patch < T > ( id , payload )
8579 }
8680
87- delete < T > ( id : string | number ) {
81+ delete < T = any > ( id : string | number ) {
8882 return this . submit < T > ( 'delete' , `/${ id } ` )
8983 }
9084
91- remove < T > ( id : string | number ) {
85+ remove < T = any > ( id : string | number ) {
9286 return this . delete < T > ( id )
9387 }
9488
95- submit < T = any > (
96- method : Method ,
97- parameter ?: string | number ,
98- form ?: T ,
99- config ?: AxiosRequestConfig ,
100- ) : Promise < T > {
89+ submit < T = any > ( method : Method , parameter ?: string | number , form ?: T , config ?: AxiosRequestConfig ) : Promise < T > {
10190 BaseService . __validateRequestType ( method )
10291 this . beforeSubmit ( )
10392 return new Promise ( ( resolve , reject ) => {
10493 const data = hasFiles ( form ) ? objectToFormData ( form ) : form
105- const endpoint = parameter
106- ? `/${ this . endpoint } /${ parameter } `
107- : `/${ this . endpoint } `
94+ const endpoint = parameter ? `/${ this . endpoint } /${ parameter } ` : `/${ this . endpoint } `
10895 const url = this . __getParameterString ( removeDoubleSlash ( endpoint ) )
10996 config = Object . assign ( { } , config , { url, data, method } )
11097 this . $http ( config )
11198 . then ( ( response : AxiosResponse ) => {
11299 this . onSuccess ( )
113- resolve ( response . data || { } )
100+ resolve ( response . data )
114101 } )
115102 . catch ( ( error : AxiosError < AxiosResponseData > ) => {
116103 this . errors . processing = false
@@ -155,8 +142,7 @@ class BaseService {
155142 ]
156143 if ( ! requestTypes . includes ( requestType ) ) {
157144 throw new Error (
158- `\`${ requestType } \` is not a valid request type, ` +
159- `must be one of: \`${ requestTypes . join ( '`, `' ) } \`.` ,
145+ `\`${ requestType } \` is not a valid request type, ` + `must be one of: \`${ requestTypes . join ( '`, `' ) } \`.` ,
160146 )
161147 }
162148 return requestType
0 commit comments