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

docs: added a service factory reference #8292

Merged
merged 5 commits into from
Jul 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ The method's names are the operation's name, suffixed by the data model's key in

For example, the following methods are generated for the service above:

<Note>

Find a complete reference of each of the methods in [this documentation](!resources!/service-factory-reference)

</Note>

<Tabs defaultValue="listMyCustoms" layoutType="vertical" className="mt-2">
<TabsList>
<TabsTrigger value="listMyCustoms">listMyCustoms</TabsTrigger>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
sidebar_label: "create"
---

export const metadata = {
title: `create Method - Service Factory Reference`,
}

# {metadata.title}

This method creates one or more records of the data model.

## Create One Record

```ts
const post = await postModuleService.createPosts({
name: "My Post",
published_at: new Date(),
metadata: {
external_id: "1234"
}
})
```

If an object is passed of the method, an object of the created record is also returned.

---

## Create Multiple Records

```ts
const posts = await postModuleService.createPosts([
{
name: "My Post",
published_at: new Date()
},
{
name: "My Other Post",
published_at: new Date()
}
])
```

If an array is passed of the method, an array of the created records is also returned.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
sidebar_label: "delete"
---

export const metadata = {
title: `delete Method - Service Factory Reference`,
}

# {metadata.title}

This method deletes one or more records.

## Delete One Record

```ts
await postModuleService.deletePosts("123")
```

To delete one record, pass its ID as a parameter of the method.

---

## Delete Multiple Records

```ts
await postModuleService.deletePosts([
"123",
"321"
])
```

To delete multiple records, pass an array of IDs as a parameter of the method.

---

## Delete Records Matching Filters

```ts
await postModuleService.deletePosts({
name: "My Post"
})
```

To delete records matching a set of filters, pass an object of filters as a parameter.

<Note>

Learn more about accepted filters in [this documentation](../../tips/filtering/page.mdx).

</Note>
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
---
sidebar_label: "list"
---

export const metadata = {
title: `list Method - Service Factory Reference`,
}

# {metadata.title}

This method retrieves a list of records.

## Retrieve List of Records

```ts
const posts = await postModuleService.listPosts()
```

If no parameters are passed, the method returns an array of the first `15` records.

---

## Filter Records

```ts
const posts = await postModuleService.listPosts({
id: ["123", "321"]
})
```

### Parameters

To retrieve records matching a set of filters, pass an object of the filters as a first parameter.

<Note>

Learn more about accepted filters in [this documentation](../../tips/filtering/page.mdx).

</Note>

### Returns

The method returns an array of the first `15` records matching the filters.

---

## Retrieve Relations

<Note>

This applies to relations between data models of the same module. To retrieve linked records of different modules, use [remote query](!docs!/advanced-development/modules/remote-query).

</Note>

```ts
const posts = await postModuleService.listPosts({}, {
relations: ["author"]
})
```

### Parameters

To retrieve records with their relations, pass as a second parameter an object having a `relations` property. `relations`'s value is an array of relation names.

### Returns

The method returns an array of the first `15` records matching the filters.

---

## Select Properties

```ts
const posts = await postModuleService.listPosts({}, {
select: ["id", "name"]
})
```

### Parameters

By default, retrieved records have all their properties. To select specific properties to retrieve, pass in the second object parameter a `select` property.

`select`'s value is an array of property names to retrieve.

### Returns

The method returns an array of the first `15` records matching the filters.

---

## Paginate Relations

```ts
const posts = await postModuleService.listPosts({}, {
take: 20,
skip: 10
})
```

### Parameters

To paginate the returned records, the second object parameter accepts the following properties:

- `take`: a number indicating how many records to retrieve. By default, it's `15`.
- `skip`: a number indicating how many records to skip before the retrieved records. By default, it's `0`.

### Returns

The method returns an array of records. The number of records is less than or equal to `take`'s value.

---

## Sort Records

```ts
const posts = await postModuleService.listPosts({}, {
order: {
name: "ASC"
}
})
```

### Parameters

To sort records by one or more properties, pass to the second object parameter the `order` property. Its value is an object whose keys are the property names, and values can either be:

- `ASC` to sort by this property in the ascending order.
- `DESC` to sort by this property in the descending order.

### Returns

The method returns an array of the first `15` records matching the filters.
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
---
sidebar_label: "listAndCount"
---

export const metadata = {
title: `listAndCount Method - Service Factory Reference`,
}

# {metadata.title}

This method retrieves a list of records with the total count.

## Retrieve List of Records

```ts
const [posts, count] = await postModuleService.listAndCountPosts()
```

If no parameters are passed, the method returns an array with two items:

1. The first is an array of the first `15` records retrieved.
2. The second is the total count of records.

---

## Filter Records

```ts
const [posts, count] = await postModuleService.listAndCountPosts({
id: ["123", "321"]
})
```

### Parameters

To retrieve records matching a set of filters, pass an object of the filters as a first parameter.

<Note>

Learn more about accepted filters in [this documentation](../../tips/filtering/page.mdx).

</Note>

### Returns

The method returns an array with two items:

1. The first is an array of the first `15` records retrieved matching the specified filters.
2. The second is the total count of records matching the specified filters.

---

## Retrieve Relations

<Note>

This applies to relations between data models of the same module. To retrieve linked records of different modules, use [remote query](!docs!/advanced-development/modules/remote-query).

</Note>

```ts
const [posts, count] = await postModuleService.listAndCountPosts({}, {
relations: ["author"]
})
```

### Parameters

To retrieve records with their relations, pass as a second parameter an object having a `relations` property. Its value is an array of relation names.

### Returns

The method returns an array with two items:

1. The first is an array of the first `15` records retrieved.
2. The second is the total count of records.

---

## Select Properties

```ts
const [posts, count] = await postModuleService.listAndCountPosts({}, {
select: ["id", "name"]
})
```

### Parameters

By default, retrieved records have all their properties. To select specific properties to retrieve, pass in the second object parameter a `select` property.

`select`'s value is an array of property names to retrieve.

### Returns

The method returns an array with two items:

1. The first is an array of the first `15` records retrieved.
2. The second is the total count of records.

---

## Paginate Relations

```ts
const [posts, count] = await postModuleService.listAndCountPosts({}, {
take: 20,
skip: 10
})
```

### Parameters

To paginate the returned records, the second object parameter accepts the following properties:

- `take`: a number indicating how many records to retrieve. By default, it's `15`.
- `skip`: a number indicating how many records to skip before the retrieved records. By default, it's `0`.

### Returns

The method returns an array with two items:

1. The first is an array of the records retrieved. The number of records is less than or equal to `take`'s value.
2. The second is the total count of records.

---

## Sort Records

```ts
const [posts, count] = await postModuleService.listAndCountPosts({}, {
order: {
name: "ASC"
}
})
```

### Parameters

To sort records by one or more properties, pass to the second object parameter the `order` property. Its value is an object whose keys are the property names, and values can either be:

- `ASC` to sort by this property in the ascending order.
- `DESC` to sort by this property in the descending order.

### Returns

The method returns an array with two items:

1. The first is an array of the first `15` records retrieved.
2. The second is the total count of records.
Loading
Loading