Skip to content

Commit ffa3d45

Browse files
authored
Merge pull request #319 from chantouchsek/feat/add-put-without-id-method
Feat/add put without id method
2 parents 38ee255 + 20439be commit ffa3d45

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/__tests__/base-proxy.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ describe('BaseProxy', () => {
330330
expect(data).toEqual(item)
331331
})
332332

333+
it('it should be able to put item without id parameter', async () => {
334+
const item = { first_name: 'Chantouch', last_name: 'Sek', id: 1 }
335+
mockAdapter.onPut('posts').reply(200, { data: item })
336+
const { data } = await proxy.putWithoutId(item)
337+
expect(data).toEqual(item)
338+
})
339+
333340
it('it should be able to patch item', async () => {
334341
const item = { first_name: 'Chantouch', last_name: 'Sek', id: 1 }
335342
mockAdapter.onPatch('posts/1').reply(200, { data: item })

src/core/BaseProxy.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ class BaseProxy {
121121
return this.submit<T>('put', `/${id}`, payload)
122122
}
123123

124+
/**
125+
* Update record without ID parameter by using PUT method
126+
* @param {Object|string} payload
127+
*/
128+
putWithoutId<T>(payload: any) {
129+
return this.submit<T>('put', '', payload)
130+
}
131+
124132
/**
125133
* Alternative of put method
126134
* @param {string|number} id

0 commit comments

Comments
 (0)