fix: update readme

This commit is contained in:
ppetzold 2021-08-19 19:29:25 +02:00
parent 6876ebca85
commit 750d7850b9

View File

@ -95,8 +95,8 @@ http://localhost:3000/cats?limit=5&page=2&sortBy=color:DESC&search=i&filter.age=
```ts
import { Controller, Injectable, Get } from '@nestjs/common'
import { InjectRepository } from '@nestjs/typeorm'
import { Repository, Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
import { FilterOperator, Paginate, PaginateQuery, paginate, Paginated } from 'nestjs-paginate'
import { Repository, Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
@Entity()
export class CatEntity {
@ -122,8 +122,8 @@ export class CatsService {
public findAll(query: PaginateQuery): Promise<Paginated<CatEntity>> {
return paginate(query, this.catsRepository, {
sortableColumns: ['id', 'name', 'color'],
searchableColumns: ['name', 'color'],
sortableColumns: ['id', 'name', 'color', 'age'],
searchableColumns: ['name', 'color', 'age'],
defaultSortBy: [['id', 'DESC']],
filterableColumns: {
age: [FilterOperator.GTE, FilterOperator.LTE],
@ -154,6 +154,14 @@ const paginateConfig: PaginateConfig<CatEntity> {
*/
sortableColumns: ['id', 'name', 'color'],
/**
* Required: false
* Type: [keyof CatEntity, 'ASC' | 'DESC'][]
* Default: [[sortableColumns[0], 'ASC]]
* Description: The order to display the sorted entities.
*/
defaultSortBy: [['name', 'DESC']],
/**
* Required: false
* Type: (keyof CatEntity)[]
@ -169,14 +177,6 @@ const paginateConfig: PaginateConfig<CatEntity> {
*/
maxLimit: 20,
/**
* Required: false
* Type: [keyof CatEntity, 'ASC' | 'DESC'][]
* Default: [[sortableColumns[0], 'ASC]]
* Description: The order to display the sorted entities.
*/
defaultSortBy: [['name', 'DESC']],
/**
* Required: false
* Type: number
@ -194,9 +194,9 @@ const paginateConfig: PaginateConfig<CatEntity> {
/**
* Required: false
* Type: FilterOperator - Based on TypeORM find operators
* Type: { [key in CatEntity]?: FilterOperator[] } - Operators based on TypeORM find operators
* Default: None
* Find more at https://typeorm.io/#/find-options/advanced-options
* https://typeorm.io/#/find-options/advanced-options
*/
filterableColumns: { age: [FilterOperator.EQ, FilterOperator.IN] }
}