From de409f0b22a2e034d02f2f7805cefad024aeacc1 Mon Sep 17 00:00:00 2001 From: Pierre Burgy Date: Wed, 8 Aug 2018 15:43:14 +0200 Subject: [PATCH 1/2] Adapt to new pluralize routes --- README.md | 12 ++++++------ src/lib/sdk.ts | 30 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 1ed4772..6e3e51a 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ await strapi.authenticateProvider('facebook'); ``` You can now fetch private APIs ```js -const posts = await strapi.getEntries('post'); +const posts = await strapi.getEntries('posts'); ``` ### Files management @@ -83,11 +83,11 @@ const files = await strapi.upload(form, { ### `authenticateProvider(provider, params)` ### `setToken(token, comesFromStorage)` ### `clearToken(token)` -### `getEntries(contentType, params)` -### `getEntry(contentType, id)` -### `createEntry(contentType, data)` -### `updateEntry(contentType, id, data)` -### `deleteEntry(contentType, id)` +### `getEntries(contentTypePluralized, params)` +### `getEntry(contentTypePluralized, id)` +### `createEntry(contentTypePluralized, data)` +### `updateEntry(contentTypePluralized, id, data)` +### `deleteEntry(contentTypePluralized, id)` ### `searchFiles(query)` ### `getFiles(params)` ### `getFile(id)` diff --git a/src/lib/sdk.ts b/src/lib/sdk.ts index afe8df5..86609c5 100644 --- a/src/lib/sdk.ts +++ b/src/lib/sdk.ts @@ -225,64 +225,64 @@ export default class Strapi { /** * List entries - * @param contentType + * @param contentTypePluralized * @param params Filter and order queries. */ public getEntries( - contentType: string, + contentTypePluralized: string, params?: AxiosRequestConfig['params'] ): Promise { - return this.request('get', `/${contentType}`, { + return this.request('get', `/${contentTypePluralized}`, { params }); } /** * Get a specific entry - * @param contentType Type of entry + * @param contentTypePluralized Type of entry pluralized * @param id ID of entry */ - public getEntry(contentType: string, id: string): Promise { - return this.request('get', `/${contentType}/${id}`); + public getEntry(contentTypePluralized: string, id: string): Promise { + return this.request('get', `/${contentTypePluralized}/${id}`); } /** * Create data - * @param contentType Type of entry + * @param contentTypePluralized Type of entry pluralized * @param data New entry */ public createEntry( - contentType: string, + contentTypePluralized: string, data: AxiosRequestConfig['data'] ): Promise { - return this.request('post', `/${contentType}`, { + return this.request('post', `/${contentTypePluralized}`, { data }); } /** * Update data - * @param contentType Type of entry + * @param contentTypePluralized Type of entry pluralized * @param id ID of entry * @param data */ public updateEntry( - contentType: string, + contentTypePluralized: string, id: string, data: AxiosRequestConfig['data'] ): Promise { - return this.request('put', `/${contentType}/${id}`, { + return this.request('put', `/${contentTypePluralized}/${id}`, { data }); } /** * Delete an entry - * @param contentType Type of entry + * @param contentTypePluralized Type of entry pluralized * @param id ID of entry */ - public deleteEntry(contentType: string, id: string): Promise { - return this.request('delete', `/${contentType}/${id}`); + public deleteEntry(contentTypePluralized: string, id: string): Promise { + return this.request('delete', `/${contentTypePluralized}/${id}`); } /** From 2034be4dc67b7bc4169d74ff1f96ea83809b70f1 Mon Sep 17 00:00:00 2001 From: Pierre Burgy Date: Wed, 8 Aug 2018 15:59:04 +0200 Subject: [PATCH 2/2] Fix tests --- src/lib/sdk.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/sdk.ts b/src/lib/sdk.ts index 86609c5..8c30eda 100644 --- a/src/lib/sdk.ts +++ b/src/lib/sdk.ts @@ -281,7 +281,10 @@ export default class Strapi { * @param contentTypePluralized Type of entry pluralized * @param id ID of entry */ - public deleteEntry(contentTypePluralized: string, id: string): Promise { + public deleteEntry( + contentTypePluralized: string, + id: string + ): Promise { return this.request('delete', `/${contentTypePluralized}/${id}`); }