Skip to content

Commit

Permalink
docs(readme): added example of returned value
Browse files Browse the repository at this point in the history
  • Loading branch information
v-checha committed May 3, 2023
1 parent aa714a6 commit 6b8224f
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 294 deletions.
79 changes: 50 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,40 @@ import { PaginatorTypes } from '@nodeteam/nestjs-prisma-pagination';
# #Paginator

## Paginator options:
**page** - `page number`
`page` - number of page

**perPage** - `records per page`
`perPage` - number of records per page

Options can be redefined

## Paginator Arguments:
**orderBy**, **where**
## Return type:

```typescript
{
data: T[],
meta: {
total: number,
lastPage: number,
currentPage: number,
perPage: number,
prev: number | null,
next: number | null,
},
}
```

## Example:

Create new paginator function with default options

```typescript
const paginate: PaginatorTypes.PaginateFunction = paginator({
page: 1,
perPage: 10,
});
```

full example:

```typescript
import PrismaService from '@providers/prisma/prisma.service';
Expand Down Expand Up @@ -57,15 +83,6 @@ export default class UserService {
}
```

#### Set options as default:

```typescript
const paginate: PaginatorTypes.PaginateFunction = paginator({
page: 1,
perPage: 10,
});
```

#### Redefine options:
```typescript
paginate(
Expand Down Expand Up @@ -94,23 +111,34 @@ https://exmaple.com/api/v1/user?page=1&where=Jake

## Search Paginator options:

**page** - `page number`
`page` - number of page

**perPage** - `records per page`
`perPage` - number of records per page

**skip** - `offset sql`
`skip` - number of records to skip

**searchColumns** - `colums where you want to find searchValue`
`searchColumns` - array of columns in db

**searchValue** - `string witch you whant to find`
`searchValue` - string to search

Options can be redefined

## Search Paginator arguments:

**model*** - `prisma service`
`model` - `PrismaClient['modelName']`

`modelName` - Name of model

create new search paginator function with default options

```typescript
const searchPaginate: PaginatorTypes.SearchPaginateFunction = searchPaginator({
page: 1,
perPage: 10,
});
```

**modelName*** - `name of table in db`
full example:

```typescript
import PrismaService from '@providers/prisma/prisma.service';
Expand Down Expand Up @@ -151,15 +179,6 @@ export default class UserService {
}
```

#### Set options as default:

```typescript
const searchPaginate: PaginatorTypes.SearchPaginateFunction = searchPaginator({
page: 1,
perPage: 10,
});
```

#### Redefine options:
```typescript
searchPaginate(
Expand All @@ -181,3 +200,5 @@ const searchPaginate: PaginatorTypes.SearchPaginateFunction = searchPaginator({
```
https://example.com/api/v1/users/full-text/search?search=Lions&page=1
```

Check useful npm packages from NodeTeam: https://www.npmjs.com/org/nodeteam
4 changes: 0 additions & 4 deletions dist/src/index.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions dist/src/prisma/paginator.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions dist/src/prisma/search-paginator.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion dist/test/prisma/paginator.spec.d.ts

This file was deleted.

102 changes: 0 additions & 102 deletions dist/test/prisma/paginator.spec.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/test/prisma/paginator.spec.js.map

This file was deleted.

1 change: 0 additions & 1 deletion dist/test/prisma/search-paginator.spec.d.ts

This file was deleted.

134 changes: 0 additions & 134 deletions dist/test/prisma/search-paginator.spec.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/test/prisma/search-paginator.spec.js.map

This file was deleted.

Loading

0 comments on commit 6b8224f

Please sign in to comment.