Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: params in delete method should be optional #900

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading