Skip to content

Commit

Permalink
feat(find/findOne): allow fetch options as third param (#360)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Canac <[email protected]>
  • Loading branch information
SvenWesterlaken and benjamincanac authored Nov 27, 2023
1 parent 7cf8737 commit b360ad3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/content/3.usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Get entries. Returns entries matching the query filters (see [parameters](https:
- **Arguments:**
- contentType: `string`
- params?: [`Strapi4RequestParams`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v4.d.ts#L24)
- fetchOptions?: [`FetchOptions`](https://github.com/unjs/ohmyfetch/blob/main/src/fetch.ts#L26)
- **Returns:** `Promise<T>`

```vue
Expand All @@ -69,6 +70,7 @@ Returns an entry by `id`.
- contentType: `string`
- id?: `string | number | Strapi4RequestParams`
- params?: [`Strapi4RequestParams`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v4.d.ts#L24)
- fetchOptions?: [`FetchOptions`](https://github.com/unjs/ohmyfetch/blob/main/src/fetch.ts#L26)
- **Returns:** `Promise<T>`

```vue
Expand Down
9 changes: 5 additions & 4 deletions src/runtime/composables-v4/useStrapi4.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Strapi4RequestParams } from '../types/v4'
import type { FetchOptions } from 'ofetch'
import { useStrapiVersion, useStrapiClient } from '#imports'

/**
Expand All @@ -19,8 +20,8 @@ export const useStrapi4 = () => {
* @param {Strapi4RequestParams} params? - Query parameters
* @returns Promise<T>
*/
const find = <T>(contentType: string, params?: Strapi4RequestParams): Promise<T> => {
return client(`/${contentType}`, { method: 'GET', params })
const find = <T>(contentType: string, params?: Strapi4RequestParams, fetchOptions?: FetchOptions): Promise<T> => {
return client(`/${contentType}`, { method: 'GET', params, ...fetchOptions })
}

/**
Expand All @@ -31,7 +32,7 @@ export const useStrapi4 = () => {
* @param {Strapi4RequestParams} params? - Query parameters
* @returns Promise<T>
*/
const findOne = <T>(contentType: string, id?: string | number | Strapi4RequestParams, params?: Strapi4RequestParams): Promise<T> => {
const findOne = <T>(contentType: string, id?: string | number | Strapi4RequestParams, params?: Strapi4RequestParams, fetchOptions?: FetchOptions): Promise<T> => {
if (typeof id === 'object') {
params = id
// @ts-ignore
Expand All @@ -40,7 +41,7 @@ export const useStrapi4 = () => {

const path = [contentType, id].filter(Boolean).join('/')

return client(path, { method: 'GET', params })
return client(path, { method: 'GET', params, ...fetchOptions })
}

/**
Expand Down

0 comments on commit b360ad3

Please sign in to comment.