Skip to content

Commit

Permalink
fix: params in delete method should be optional (#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
edodusi authored Dec 18, 2024
1 parent e496881 commit f99c6e8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Storyblok.post(`spaces/${spaceId}/stories`, {
Storyblok.put(`spaces/${spaceId}/stories/1`, {
story: { name: "xy", slug: "xy" },
});
Storyblok.delete(`spaces/${spaceId}/stories/1`, null);
Storyblok.delete(`spaces/${spaceId}/stories/1`);
```

### Using the RichTextResolver separately
Expand Down Expand Up @@ -402,7 +402,7 @@ Storyblok.put('spaces/<YOUR_SPACE_ID>/stories/1', {
**Example**

```javascript
Storyblok.delete('spaces/<YOUR_SPACE_ID>/stories/1', null)
Storyblok.delete('spaces/<YOUR_SPACE_ID>/stories/1')
.then((response) => {
console.log(response)
})
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ class Storyblok {
params: ISbStoriesParams | ISbContentMangmntAPI,
fetchOptions?: ISbCustomFetch,
): Promise<ISbResponseData> {
if (!params) {
params = {} as ISbStoriesParams;
}
const url = `/${slug}`;

return Promise.resolve(
Expand Down
2 changes: 1 addition & 1 deletion src/sbFetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('sbFetch', () => {
status: 204, // Typically, DELETE operations might not return content
});
mockFetch.mockResolvedValue(response);
await sbFetch.delete('stories/1', {});
await sbFetch.delete('stories/1');
expect(mockFetch).toHaveBeenCalledWith(
'https://api.storyblok.com/v2/stories/1',
{
Expand Down
4 changes: 2 additions & 2 deletions src/sbFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class SbFetch {
return this._methodHandler('put');
}

public delete(url: string, params: ISbStoriesParams) {
public delete(url: string, params?: ISbStoriesParams) {
this.url = url;
this.parameters = params;
this.parameters = params ?? {} as ISbStoriesParams;
return this._methodHandler('delete');
}

Expand Down

0 comments on commit f99c6e8

Please sign in to comment.