# @motech-development/pagination

> NestJS pagination utility

Latest version **1.0.6** (published 2022-06-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @motech-development/pagination
pnpm add @motech-development/pagination
yarn add @motech-development/pagination
bun add @motech-development/pagination
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2022-06-19 |
| First published | 2022-01-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 30.6 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| Author | Mo Gusbi |
| Maintainers | mogusbi |

## Links

- npm: https://www.npmjs.com/package/@motech-development/pagination
- Repository: https://github.com/motech-development/microservices
- Homepage: https://github.com/motech-development/microservices/tree/main/packages/pagination#readme
- Issues: https://github.com/motech-development/microservices/issues
- npm.io page: https://npm.io/package/@motech-development/pagination

## Dependencies (5)

- [rxjs](https://npm.io/package/rxjs.md) ^7.4.0
- [express](https://npm.io/package/express.md) ^4.17.1
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) ^8.1.1
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^8.1.1
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## Recent versions

- 1.0.6 (latest) — 2022-06-19
- 1.0.5 — 2022-04-14
- 1.0.4 — 2022-02-19
- 1.0.3 — 2022-02-02
- 1.0.2 — 2022-02-02
- 1.0.1 — 2022-01-11
- 1.0.0 — 2022-01-09

## README

[npm]: https://img.shields.io/npm/v/@motech-development/pagination
[npm-url]: https://www.npmjs.com/package/@motech-development/pagination
[size]: https://packagephobia.now.sh/badge?p=@motech-development/pagination
[size-url]: https://packagephobia.now.sh/result?p=@motech-development/pagination
[sonar]: https://sonarcloud.io/api/project_badges/measure?project=motech-development_microservices_4&metric=alert_status
[sonar-url]: https://sonarcloud.io/summary/new_code?id=motech-development_microservices_4

[![npm][npm]][npm-url]
[![size][size]][size-url]
[![sonar][sonar]][sonar-url]

# @motech-development/pagination

> NestJS pagination utility

This utility provides an interceptor and decorator that, in conjunction, allow you to quickly convert query string parameters into paginated inputs for querying data.

## Installation

Add `@motech-development/pagination` as a dependency.

```bash
# Yarn
yarn add @motech-development/pagination

# NPM
npm i @motech-development/pagination
```

## Usage

Add the `PaginationModule` to your application.

```typescript
import { PaginationModule } from '@motech-development/pagination';

@Module({
  imports: [PaginationModule],
})
class AppModule {}
```

This module will then make the `PaginationInterceptor` and `Pagination` decorator available to use in your controllers.

```typescript
import {
  IPaginated,
  Pagination,
  PaginationInterceptor,
} from '@motech-development/pagination';

@Controller()
class AppController {
  @Get()
  @UseInterceptors(PaginationInterceptor)
  public get(@Pagination() data: IPaginated): IPaginated {
    return data;
  }
}
```

The pagination decorator accepts the following query string parameters; `dir`, `limit`, `page`, `sortBy`. If not set `dir` defaults to `descending`, `limit` to `10` and `page` to `1`.

The output will be the following object.

```typescript
interface IOutput {
  orderBy: {
    [name: string]: 'asc' | 'desc';
  };
  skip: number;
  take: number;
}
```

---
_Source: https://npm.io/package/@motech-development/pagination · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
