Skip to content

Commit

Permalink
chore(useStrapi): add optional query params to create / update in…
Browse files Browse the repository at this point in the history
… `v5` (#426)
  • Loading branch information
BayBreezy authored Sep 30, 2024
1 parent 84b7e19 commit 0488bed
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/runtime/composables-v5/useStrapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ export const useStrapi = <T>(): StrapiV5Client<T> => {
*
* @param {string} contentType - Content type's name pluralized
* @param {Record<string, any>} data - Form data
* @param {Strapi5RequestParams} [params] - Query parameters
* @returns Promise<T>
*/
const create = <T>(contentType: string, data: Partial<T>): Promise<Strapi5ResponseSingle<T>> => {
return client(`/${contentType}`, { method: 'POST', body: { data } })
const create = <T>(contentType: string, data: Partial<T>, params: Strapi5RequestParams = {}): Promise<Strapi5ResponseSingle<T>> => {
return client(`/${contentType}`, { method: 'POST', body: { data }, params })
}

/**
Expand All @@ -61,17 +62,18 @@ export const useStrapi = <T>(): StrapiV5Client<T> => {
* @param {string} contentType - Content type's name pluralized
* @param {string} documentId - ID of entry to be updated
* @param {Record<string, any>} data - Form data
* @param {Strapi5RequestParams} [params] - Query parameters
* @returns Promise<T>
*/
const update = <T>(contentType: string, documentId: string | Partial<T>, data?: Partial<T>): Promise<Strapi5ResponseSingle<T>> => {
const update = <T>(contentType: string, documentId: string | Partial<T>, data?: Partial<T>, params: Strapi5RequestParams = {}): Promise<Strapi5ResponseSingle<T>> => {
if (typeof documentId === 'object') {
data = documentId
documentId = undefined
}

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

return client(path, { method: 'PUT', body: { data } })
return client(path, { method: 'PUT', body: { data }, params })
}

/**
Expand Down

0 comments on commit 0488bed

Please sign in to comment.