Gathering detailed insights and metrics for @forlagshuset/nestjs-mongoose-paginate
Gathering detailed insights and metrics for @forlagshuset/nestjs-mongoose-paginate
Gathering detailed insights and metrics for @forlagshuset/nestjs-mongoose-paginate
Gathering detailed insights and metrics for @forlagshuset/nestjs-mongoose-paginate
npm install @forlagshuset/nestjs-mongoose-paginate
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
16 Stars
134 Commits
10 Forks
7 Watching
21 Branches
10 Contributors
Updated on 08 Oct 2024
TypeScript (96%)
JavaScript (4%)
Cumulative downloads
Total Downloads
Last day
64.1%
64
Compared to previous day
Last week
35.2%
396
Compared to previous week
Last month
-9.4%
1,557
Compared to previous month
Last year
46.7%
16,991
Compared to previous year
8
A pagination, filtering and sorting lib for nestjs v8(for v7 please use < v1.1) using mongoose orm
Create a class to hold information about filterable and sortable properties
You need to @Expose
properties of this class. By default none of it is filterable nor sortable.
You should set this parameters explicitly.
In case you want to expose some of the properties with a different name, you need to specify a name
option in this decorator.
1import { 2 CollectionProperties, 3 Expose 4} from '@forlagshuset/nestjs-mongoose-paginate'; 5 6export class MyCollectionProperties extends CollectionProperties { 7 @Expose({ name: 'createdAt', sortable: true }) 8 readonly created_at: 'desc' | 'asc'; 9 10 @Expose({ sortable: true, default: true, filterable: true }) 11 readonly userName: 'desc' | 'asc'; 12 13 readonly unsortable: string; 14}
1import { 2 CollectionDto, 3 ValidationPipe, 4 CollectionResponse 5} from '@forlagshuset/nestjs-mongoose-paginate'; 6 7@Controller() 8export class AppController { 9 @Get('list') 10 async filter( 11 @Query(new ValidationPipe(MyCollectionProperties)) 12 collectionDto: CollectionDto, 13 ): Promise<CollectionResponse<MyDocument>> { 14 return await this.service.list(collectionDto); 15 } 16}
1import { Model } from 'mongoose'; 2import { InjectModel } from '@nestjs/mongoose'; 3import { 4 CollectionDto, 5 DocumentCollector, 6 CollectionResponse 7} from '@forlagshuset/nestjs-mongoose-paginate'; 8 9@Injectable() 10export class AppService { 11 constructor( 12 @InjectModel('MyModel') private readonly model: Model<MyDocument>, 13 ) 14 15 async list( 16 collectionDto: CollectionDto, 17 ): Promise<CollectionResponse<MyDocument>> { 18 const collector = new DocumentCollector<MyDocument>(this.model); 19 return collector.find(collectionDto); 20 } 21}
You may now send a request, like in example below:
http://localhost:3000/list?filter={"userName": {"$regex": "^test"}}&sort=-createdAt&page=0&limit=100
You need to run the parameters through urlencode
to be able to parse the query correctly. So the filter part looks more like
%7B%22userName%22%3A%20%7B%22%24regex%22%3A%20%22%5Etest%22%7D%7D
You can specify more than one field for sorting by providing a list of them separated by a semicolon: createdAt;userName
.
To use DESC sort order: -createdAt
.
A subset of mongoose query language is supported. Currently only these operators are supported:
'$eq', '$gt', '$gte', '$in', '$lt', '$lte', '$ne', '$nin', '$and', '$not', '$nor', '$or', '$regex'
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
11 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 9
Reason
3 existing vulnerabilities detected
Details
Reason
Found 8/17 approved changesets -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More