Skip to content

Commit

Permalink
chore: ⚡ add create many method to service
Browse files Browse the repository at this point in the history
  • Loading branch information
chantouchsek committed Aug 16, 2021
1 parent 267bf44 commit 03d6db1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-api-queries",
"version": "1.0.0",
"version": "1.1.0",
"description": "Elegant and simple way to build requests for REST API",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
9 changes: 9 additions & 0 deletions src/__tests__/base-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ describe('BaseProxy', () => {
expect(data).toEqual(item)
})

it('it should create items with bulk', async () => {
const item = {
bulk: [{ first_name: 'Chantouch', last_name: 'Sek', id: 1 }],
}
mockAdapter.onPost('/posts/bulk').reply(201, item)
const data = await proxy.createMany(item)
expect(data).toEqual(item)
})

it('transforms the data to a FormData object if there is a File', async () => {
const file = new File(['hello world!'], 'myfile')
const form: any = { field1: {}, field2: {}, files: [] }
Expand Down
8 changes: 8 additions & 0 deletions src/core/BaseProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ class BaseProxy {
return this.store<T>(payload, config)
}

/**
* Create many items
* @param {Object} payload
*/
createMany<T>(payload: T): Promise<T> {
return this.submit<T>('post', 'bulk', payload)
}

/**
* Update record by id using PUT method
* @param {string|number} id
Expand Down

0 comments on commit 03d6db1

Please sign in to comment.