Skip to content

Commit 47f65cb

Browse files
committed
chore(break)!: remove unused methods
1 parent 4fb5adb commit 47f65cb

File tree

4 files changed

+45
-27
lines changed

4 files changed

+45
-27
lines changed

jest.config.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ const config: InitialOptionsTsJest = {
55
collectCoverageFrom: ['src/**/*.ts', 'src/**/*.js'],
66
coverageThreshold: {
77
global: {
8-
lines: 100,
9-
functions: 100,
10-
branches: 92.72,
11-
statements: 99.33,
8+
branches: 93,
9+
statements: 99,
1210
},
1311
},
1412
testEnvironment: 'node',

src/__tests__/base-proxy.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ describe('BaseProxy', () => {
209209
return [200, {}]
210210
})
211211

212-
await proxy.create(form)
212+
await proxy.store(form)
213213
})
214214

215215
it('transforms the data to a FormData object if there is a File with post', async () => {
@@ -241,7 +241,7 @@ describe('BaseProxy', () => {
241241
return [200, {}]
242242
})
243243

244-
await proxy.putWithFile(form.id, form)
244+
await proxy.put(form.id, form)
245245
})
246246

247247
it('transforms the boolean values in FormData object to "1" or "0"', async () => {
@@ -306,7 +306,7 @@ describe('BaseProxy', () => {
306306
it('it should be able to put item without id parameter', async () => {
307307
const item = { first_name: 'Chantouch', last_name: 'Sek', id: 1 }
308308
mockAdapter.onPut('posts').reply(200, { data: item })
309-
const { data } = await proxy.putWithoutId(item)
309+
const { data } = await proxy.put(item)
310310
expect(data).toEqual(item)
311311
})
312312

@@ -317,6 +317,13 @@ describe('BaseProxy', () => {
317317
expect(data).toEqual(item)
318318
})
319319

320+
it('it should be able to patch item without id', async () => {
321+
const item = { first_name: 'Chantouch', last_name: 'Sek', id: 1 }
322+
mockAdapter.onPatch('posts').reply(200, { data: item })
323+
const { data } = await proxy.patch(item)
324+
expect(data).toEqual(item)
325+
})
326+
320327
it('it should be able to update an item', async () => {
321328
const item = { first_name: 'Chantouch', last_name: 'Sek', id: 1 }
322329
mockAdapter.onPatch('posts/1').reply(200, { data: item })

src/__tests__/post-proxy.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ describe('PostProxy', () => {
2929
items: data,
3030
pagination: meta.pagination,
3131
}
32-
console.warn('meta', item.pagination)
3332
expect(meta).toHaveProperty('pagination')
3433
expect(data.length).toEqual(1)
3534
expect(item.pagination.page).toEqual(1)

src/core/BaseProxy.ts

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import type {
77
} from 'axios'
88
import type { Errors } from '..'
99
import Validator from './Validator'
10-
import { hasFiles, objectToFormData, removeDoubleSlash } from '../util'
10+
import {
11+
hasFiles,
12+
objectToFormData,
13+
removeDoubleSlash,
14+
isObject,
15+
} from '../util'
1116
import qs, { IParseOptions } from 'qs'
1217

1318
const 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

Comments
 (0)