Skip to content

Commit

Permalink
chore: id not optional on update as data is required
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac committed Jan 19, 2023
1 parent e26e433 commit 27d9e57
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/content/3.usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Partially updates an entry by `id` and returns its value. Fields that aren't sen

- **Arguments:**
- contentType: `string`
- id?: `string | number | Partial<T>`
- id: `string | number | Partial<T>`
- data?: `Partial<T>`
- **Returns:** `Promise<T>`

Expand All @@ -135,7 +135,7 @@ const onSubmit = async () => {
```

::alert{type="info"}
This method can be used to update/create a single type entry as `id` is optional.
This method can be used to update/create a single type entry as you can pass the `data` instead of the `id`.
::

> Check out the Strapi [Update an entry](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest-api.html#update-an-entry) REST API endpoint.
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables-v3/useStrapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface StrapiV3Client<T> {
find<F = T[]>(contentType: string, params?: Strapi3RequestParams): Promise<F>
findOne<F = T>(contentType: string, id?: string | number | Strapi3RequestParams, params?: Strapi3RequestParams): Promise<F>
create<F = T>(contentType: string, data: Partial<F>): Promise<F>
update<F = T>(contentType: string, id?: string | number | Partial<F>, data?: Partial<F>): Promise<F>
update<F = T>(contentType: string, id: string | number | Partial<F>, data?: Partial<F>): Promise<F>
delete<F = T>(contentType: string, id?: string | number): Promise<F>
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables-v3/useStrapi3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const useStrapi3 = () => {
* @param {Record<string, any>} data - Form data
* @returns Promise<T>
*/
const update = <T>(contentType: string, id?: string | number | Partial<T>, data?: Partial<T>): Promise<T> => {
const update = <T>(contentType: string, id: string | number | Partial<T>, data?: Partial<T>): Promise<T> => {
if (typeof id === 'object') {
data = id
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables-v4/useStrapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface StrapiV4Client<T> {
find<F = T>(contentType: string, params?: Strapi4RequestParams): Promise<Strapi4ResponseMany<F>>
findOne<F = T>(contentType: string, id?: string | number | Strapi4RequestParams, params?: Strapi4RequestParams): Promise<Strapi4ResponseSingle<F>>
create<F = T>(contentType: string, data: Partial<F>): Promise<Strapi4ResponseSingle<F>>
update<F = T>(contentType: string, id?: string | number | Partial<F>, data?: Partial<F>): Promise<Strapi4ResponseSingle<F>>
update<F = T>(contentType: string, id: string | number | Partial<F>, data?: Partial<F>): Promise<Strapi4ResponseSingle<F>>
delete<F = T>(contentType: string, id?: string | number): Promise<Strapi4ResponseSingle<F>>
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables-v4/useStrapi4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const useStrapi4 = () => {
* @param {Record<string, any>} data - Form data
* @returns Promise<T>
*/
const update = <T>(contentType: string, id?: string | number | Partial<T>, data?: Partial<T>): Promise<T> => {
const update = <T>(contentType: string, id: string | number | Partial<T>, data?: Partial<T>): Promise<T> => {
if (typeof id === 'object') {
data = id
// @ts-ignore
Expand Down

0 comments on commit 27d9e57

Please sign in to comment.