Skip to content
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
2 changes: 1 addition & 1 deletion docs/content/1.guide/4.repository/5.deleting-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You may delete existing data through various repository methods.

In this section, it assumes you're familiar with the usage of repository. If not, please read through the [Repository: Getting Started](./1.getting-started) page first.

## Deleting Data
## Deleting Data by id

To delete a record, you may use the `destroy` method and pass the primary key for the record to be deleted.

Expand Down
16 changes: 8 additions & 8 deletions docs/content/3.plugins/2.axios/1.guide/2.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ useAxiosRepo(User).api().get('/api/users', {
})
```

Request configurations vary depending on the type of request being made. Please refer to the [Usage Guide](usage) to read more.
Request configurations vary depending on the type of request being made. Please refer to the [Usage Guide](/plugins/axios/guide/usage) to read more.


## Available Options
Expand Down Expand Up @@ -115,7 +115,7 @@ In addition to [axios request options](https://github.com/axios/axios#request-co

This option will let you intercept and transform the response before persisting it to the store.

The method will receive a [Response](usage.md#handling-responses) object allowing you to access response properties such as response headers, as well as manipulate the data as you see fit.
The method will receive a [Response](/plugins/axios/guide/usage#handling-responses) object allowing you to access response properties such as response headers, as well as manipulate the data as you see fit.

Any method defined must return data to pass on to Pinia ORM.

Expand All @@ -136,7 +136,7 @@ In addition to [axios request options](https://github.com/axios/axios#request-co
Using the `dataTransformer` option will ignore any `dataKey` option.
:::

**See also**: [Transforming Data](usage.md#transforming-data)
**See also**: [Transforming Data](/plugins/axios/guide/usage#transforming-data)

### `persistBy`

Expand All @@ -158,18 +158,18 @@ In addition to [axios request options](https://github.com/axios/axios#request-co

By setting this option to `false`, the response data will not be persisted and you will have to handle persistence alternatively. The `entities` property in the [Response](usage.md#handling-responses) object will also be `null` since it will no longer be persisting data automatically.

**See also**: [Deferring Persistence](usage.md#deferring-persistence)
**See also**: [Deferring Persistence](/plugins/axios/guide/usage#deferring-persistence)

### `delete`

- **Type**: `string | number | (model: Model) => boolean`
- **Type**: `string | number`
- **Default**: `undefined`

This option is primarily used with delete requests. It's argument signature is identical to the [Pinia ORM delete](https://vuex-orm.org/guide/data/deleting) method by which a primary key can be set as the value, or passing a predicate function. The corresponding record will be removed from the store after the request is made.
This option is primarily used with delete requests. It's argument signature is identical to the [Pinia ORM delete](/guide/repository/deleting-data#deleting-data-by-id) method by which a primary key can be set as the value. The corresponding record will be removed from the store after the request is made.

Setting this option will ignore any `save` options you may have set and therefore persistence is not possible when using this option.

**See also**: [Delete Requests](usage.md#delete-requests)
**See also**: [Delete Requests](/plugins/axios/guide/usage#delete-requests)

### `actions`

Expand All @@ -178,4 +178,4 @@ In addition to [axios request options](https://github.com/axios/axios#request-co

This option allows for your own predefined api methods.

Please refer to the [Custom Actions](custom-actions) documentation to learn more.
Please refer to the [Custom Actions](/plugins/axios/guide/custom-actions) documentation to learn more.
2 changes: 1 addition & 1 deletion docs/content/3.plugins/2.axios/1.guide/2.usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ useAxiosRepo(User).api().get('/api/users', { persistBy: 'insert' })
When performing a `delete` request, the plugin will not remove the corresponding entities from the store. It is not always possible to determine which record is to be deleted and often HTTP DELETE requests are performed on a resource URL.
:::

If you want to delete a record from the store after performing a delete request, you must pass the `delete` option.
If you want to delete a record from the store after performing a delete request, you must pass the `delete` option with the ID of the entity.

```js
useAxiosRepo(User).api().delete('/api/users/1', {
Expand Down
2 changes: 1 addition & 1 deletion packages/axios/.eslintcache

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/axios/src/composables/useAxiosRepo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Model } from 'pinia-orm'
import type { Constructor, Model } from 'pinia-orm'
import { useRepo } from 'pinia-orm'
import { getActivePinia } from 'pinia'
import { AxiosRepository } from '../repository/AxiosRepository'

export function useAxiosRepo<M extends Model> (model: M) {
export function useAxiosRepo<M extends Model> (model: Constructor<M>) {
const pinia = getActivePinia()
AxiosRepository.useModel = model as unknown as typeof Model
return useRepo(AxiosRepository<Model>, pinia)
Expand Down
9 changes: 7 additions & 2 deletions packages/axios/src/types/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Element, Model } from 'pinia-orm'
import type { Element } from 'pinia-orm'
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'

export type PersistMethods = 'save' | 'insert'
Expand All @@ -14,7 +14,12 @@ export interface Config extends AxiosRequestConfig {
save?: boolean
persistBy?: PersistMethods
persistOptions?: PersistOptions
delete?: string | number | ((model: Model) => boolean)
/**
* This tells the api to delete the record from the store after the call is finished.
*
* It needs the `primaryKey` value (ID) of the entity as argument.
*/
delete?: string | number
actions?: {
[name: string]: any
}
Expand Down
2 changes: 1 addition & 1 deletion packages/axios/test/feature/Response_Delete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('Feature - Response - Save', () => {

try {
await response.delete()
} catch (e) {
} catch (e: any) {
expect(e.message).toBe(
'[Pinia ORM Axios] Could not delete records because the `delete` option is not set.',
)
Expand Down
2 changes: 1 addition & 1 deletion packages/pinia-orm/.eslintcache

Large diffs are not rendered by default.