Skip to content

Commit

Permalink
feat: new types
Browse files Browse the repository at this point in the history
  • Loading branch information
Intevel committed Mar 26, 2022
1 parent ca45774 commit 428d985
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
62 changes: 62 additions & 0 deletions docs/content/en/usage/useDirectusItems.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
title: "useDirectusItems"
description: "Learn how to use Nuxt & Directus"
position: 10
category: "Usage"
---

> Check out the Directus [Items](https://docs.directus.io/reference/items/) documentation.
### `getItems`

Search for items in a specific collection, [`global search querys`](https://docs.directus.io/reference/query/) can be used

- **Arguments:**

- data: [`DirectusItemRequest`](https://github.com/Intevel/nuxt-directus/blob/master/src/runtime/types/index.d.ts#L26)

- **Returns:** `Array`

```vue [pages/articles.vue]
<script setup lang="ts">
const { getItems } = useDirectusAuth();
const router = useRouter();
const fetchArticles = async () => {
try {
var filters = { content: "testcontent", title: "Test1" };
var items = await getItems({
collection: "News",
params: {
filter: filters,
},
});
} catch (e) {}
};
</script>
```

### `getItemById`

Search for an item by id in a specific collection

- **Arguments:**

- data: [`DirectusItemRequest`](https://github.com/Intevel/nuxt-directus/blob/master/src/runtime/types/index.d.ts#L26)

- **Returns:** `Object`

```vue [pages/article.vue]
<script setup lang="ts">
const { getItemById } = useDirectusAuth();
const fetchArticle = async () => {
try {
var item = await getItemById({
collection: "News",
id: "4776864a-75ee-4746-9ef4-bd5c2e38cc66",
});
} catch (e) {}
};
</script>
```
5 changes: 5 additions & 0 deletions src/runtime/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export interface DirectusItemRequest {
params?: DirectusQueryParams;
}

export interface DirectusItemCreation {
collection: string;
items: Array<Object> | Object;
}

export interface DirectusQueryParams {
fields?: Array<string>;
sort?: string | Array<string>;
Expand Down

0 comments on commit 428d985

Please sign in to comment.