@motech-development/pagination
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

npm size sonar

@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.

# Yarn
yarn add @motech-development/pagination

# NPM
npm i @motech-development/pagination

Usage

Add the PaginationModule to your application.

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.

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.

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

Readme

Keywords

none

Package Sidebar

Install

npm i @motech-development/pagination

Weekly Downloads

0

Version

1.0.6

License

MIT

Unpacked Size

31.3 kB

Total Files

12

Last publish

Collaborators

  • mogusbi