Skip to content

Commit 8d8eda3

Browse files
committed
feat(kitsu): patch - add params parameter
BREAKING CHANGE
1 parent 13686be commit 8d8eda3

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

packages/kitsu/src/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ export default class Kitsu {
215215
* @memberof Kitsu
216216
* @param {string} model Model to update data in
217217
* @param {Object|Object[]} body Data to send in the request
218-
* @param {Object} [headers] Additional headers to send with the request
218+
* @param {Object} [config] Additional configuration
219+
* @param {Object} [config.params] JSON:API request queries. See [#get](#get) for documentation
220+
* @param {Object} [config.headers] Additional headers to send with the request
219221
* @returns {Object|Object[]} JSON-parsed response
220222
* @example <caption>Update a resource</caption>
221223
* api.update('posts', {
@@ -240,8 +242,10 @@ export default class Kitsu {
240242
* { id: '2', content: 'Another post' }
241243
* ])
242244
*/
243-
async patch (model, body, headers = {}) {
245+
async patch (model, body, config = {}) {
244246
try {
247+
const headers = merge(this.headers, config.headers)
248+
const params = merge({}, config.params)
245249
const [ resourceModel, url ] = splitModel(model, {
246250
resourceCase: this.resCase,
247251
pluralModel: this.plural
@@ -254,7 +258,11 @@ export default class Kitsu {
254258
const { data } = await this.axios.patch(
255259
fullURL,
256260
serialData,
257-
{ headers: Object.assign(this.headers, headers) }
261+
{
262+
headers,
263+
params,
264+
paramsSerializer: /* istanbul ignore next */ p => query(p)
265+
}
258266
)
259267

260268
return deserialise(data)

packages/kitsu/src/patch.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('kitsu', () => {
2626
})
2727
return [ 200 ]
2828
})
29-
api.patch('anime', { id: '1', type: 'anime' }, { extra: true }).catch(err => {
29+
api.patch('anime', { id: '1', type: 'anime' }, { headers: { extra: true } }).catch(err => {
3030
done.fail(err)
3131
})
3232
done()

0 commit comments

Comments
 (0)