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

chore(useStrapi): add optional query params to create / update in v5 #426

Merged
Merged
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
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>> => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

U probably wanted to assign the params to the client. In that case u'd fix pipelines.
return client(path, { method: 'PUT', body: { data }, params })

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty. Idk how i missed that lol

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
Loading