11import axios from 'axios'
22import pluralise from 'pluralize'
3- import { camel , deserialise , error , kebab , query , serialise , snake } from 'kitsu-core'
3+ import { camel , deserialise , error , kebab , query , serialise , snake , splitModel } from 'kitsu-core'
44
55/**
66 * Creates a new `kitsu` instance
@@ -218,13 +218,16 @@ export default class Kitsu {
218218 */
219219 async patch ( model , body , headers = { } ) {
220220 try {
221- const serialData = serialise ( model , body , 'PATCH' , {
221+ const [ resourceModel , url ] = splitModel ( model , {
222+ resourceCase : this . resCase ,
223+ pluralModel : this . plural
224+ } )
225+ const serialData = serialise ( resourceModel , body , 'PATCH' , {
222226 camelCaseTypes : this . camel ,
223227 pluralTypes : this . plural
224228 } )
225- const url = this . plural ( this . resCase ( model ) ) + '/' + body . id
226229 const { data } = await this . axios . patch (
227- url ,
230+ ` ${ url } / ${ body . id } ` ,
228231 serialData ,
229232 { headers : Object . assign ( this . headers , headers ) }
230233 )
@@ -258,10 +261,13 @@ export default class Kitsu {
258261 */
259262 async post ( model , body , headers = { } ) {
260263 try {
261- const url = this . plural ( this . resCase ( model ) )
264+ const [ resourceModel , url ] = splitModel ( model , {
265+ resourceCase : this . resCase ,
266+ pluralModel : this . plural
267+ } )
262268 const { data } = await this . axios . post (
263269 url ,
264- serialise ( model , body , 'POST' , {
270+ serialise ( resourceModel , body , 'POST' , {
265271 camelCaseTypes : this . camel ,
266272 pluralTypes : this . plural
267273 } ) ,
@@ -287,9 +293,12 @@ export default class Kitsu {
287293 */
288294 async delete ( model , id , headers = { } ) {
289295 try {
290- const url = this . plural ( this . resCase ( model ) ) + '/' + id
291- const { data } = await this . axios . delete ( url , {
292- data : serialise ( model , { id } , 'DELETE' , {
296+ const [ resourceModel , url ] = splitModel ( model , {
297+ resourceCase : this . resCase ,
298+ pluralModel : this . plural
299+ } )
300+ const { data } = await this . axios . delete ( `${ url } /${ id } ` , {
301+ data : serialise ( resourceModel , { id } , 'DELETE' , {
293302 camelCaseTypes : this . camel ,
294303 pluralTypes : this . plural
295304 } ) ,
0 commit comments