1.0.6 • Published 2 years ago

@motech-development/pagination v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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;
}
1.0.6

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago