Skip to content

Commit 03d6db1

Browse files
committed
chore: ⚡ add create many method to service
1 parent 267bf44 commit 03d6db1

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-api-queries",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Elegant and simple way to build requests for REST API",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/__tests__/base-proxy.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ describe('BaseProxy', () => {
193193
expect(data).toEqual(item)
194194
})
195195

196+
it('it should create items with bulk', async () => {
197+
const item = {
198+
bulk: [{ first_name: 'Chantouch', last_name: 'Sek', id: 1 }],
199+
}
200+
mockAdapter.onPost('/posts/bulk').reply(201, item)
201+
const data = await proxy.createMany(item)
202+
expect(data).toEqual(item)
203+
})
204+
196205
it('transforms the data to a FormData object if there is a File', async () => {
197206
const file = new File(['hello world!'], 'myfile')
198207
const form: any = { field1: {}, field2: {}, files: [] }

src/core/BaseProxy.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ class BaseProxy {
9696
return this.store<T>(payload, config)
9797
}
9898

99+
/**
100+
* Create many items
101+
* @param {Object} payload
102+
*/
103+
createMany<T>(payload: T): Promise<T> {
104+
return this.submit<T>('post', 'bulk', payload)
105+
}
106+
99107
/**
100108
* Update record by id using PUT method
101109
* @param {string|number} id

0 commit comments

Comments
 (0)