@hedhog/pagination 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
package/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# <p align="center">hedhog/pagination</p>
|
2
|
+
|
3
|
+
<p align="center">
|
4
|
+
<img src="https://avatars.githubusercontent.com/u/177489127?s=200&v=4" alt="Hedhog Avatar" />
|
5
|
+
</p>
|
6
|
+
|
7
|
+
**Hedhog Pagination** is a powerful and flexible pagination library designed for use with HedHog-based projects. It simplifies the process of paginating data results from your database queries, making it easy to handle large datasets and provide users with a smooth and efficient browsing experience.
|
8
|
+
|
9
|
+
## Features
|
10
|
+
|
11
|
+
- **Flexible Pagination**: Supports pagination with configurable page sizes and sorting options.
|
12
|
+
- **Search Functionality**: Enables search functionality within paginated results.
|
13
|
+
- **Field Selection**: Allows selecting specific fields to be returned in the results.
|
14
|
+
- **Sorting**: Provides sorting capabilities based on specified fields and order.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
This library is an integral part of the HedHog framework and should be installed as a dependency in your HedHog project. Ensure that the necessary dependencies are configured in your HedHog project.
|
19
|
+
|
20
|
+
```bash
|
21
|
+
npm i @hedhog/pagination
|
22
|
+
```
|
23
|
+
|
24
|
+
## Folder Structure
|
25
|
+
|
26
|
+
```plaintext
|
27
|
+
pagination/
|
28
|
+
├── dist/ # Compiled JavaScript files from build
|
29
|
+
├── node_modules/ # Discardable folder with all module dependencies
|
30
|
+
├── src/
|
31
|
+
│ ├── constants/
|
32
|
+
│ │ └── pagination.constants.ts # Constants related to pagination
|
33
|
+
│ ├── decorator/
|
34
|
+
│ │ └── pagination.decorator.ts # Decorators for pagination
|
35
|
+
│ ├── dto/
|
36
|
+
│ │ └── pagination.dto.ts # Data Transfer Object for pagination parameters
|
37
|
+
│ ├── enums/
|
38
|
+
│ │ └── pagination.enums.ts # Enums for pagination
|
39
|
+
│ ├── types/
|
40
|
+
│ │ └── pagination.types.ts # Type definitions for pagination
|
41
|
+
│ ├── index.ts # Entry point for pagination files
|
42
|
+
│ ├── pagination.module.ts # Module definition for pagination functionalities
|
43
|
+
│ ├── pagination.service.spec.ts # Unit tests for PaginationService
|
44
|
+
│ └── pagination.service.ts # Service class for pagination logic
|
45
|
+
├── .gitignore # Specifies which files Git should ignore
|
46
|
+
├── package.json # Manages dependencies and scripts for the library
|
47
|
+
├── package-lock.json # Lock file for dependencies
|
48
|
+
├── README.md # Documentation for the library
|
49
|
+
├── tsconfig.lib.json # TypeScript configuration for library builds
|
50
|
+
├── tsconfig.production.json # TypeScript configuration for production builds
|
51
|
+
```
|
52
|
+
|
53
|
+
## Usage Example
|
54
|
+
|
55
|
+
The core of the `@hedhog/pagination` library is the PaginationService. It provides the paginate method to handle pagination logic for your models.
|
56
|
+
|
57
|
+
```typescript
|
58
|
+
import { Injectable } from '@nestjs/common';
|
59
|
+
import { PaginationService } from '@hedhog/pagination';
|
60
|
+
import { PrismaService } from '@hedhog/prisma';
|
61
|
+
|
62
|
+
@Injectable()
|
63
|
+
export class MyService {
|
64
|
+
constructor(
|
65
|
+
private readonly paginationService: PaginationService,
|
66
|
+
private readonly prismaService: PrismaService,
|
67
|
+
) {}
|
68
|
+
|
69
|
+
async getPaginatedResults(paginationParams: PaginationParams) {
|
70
|
+
const model = this.prismaService.myModel; // Replace with your model
|
71
|
+
return this.paginationService.paginate(model, paginationParams);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
```
|
75
|
+
|
76
|
+
## Parameters
|
77
|
+
|
78
|
+
- **model**: The model to paginate, typically from your ORM (e.g., Prisma).
|
79
|
+
- **paginationParams**: An object containing pagination parameters:
|
80
|
+
- **page**: The current page number (default: 1).
|
81
|
+
- **pageSize**: The number of items per page (default: 10).
|
82
|
+
- **search**: The search query string.
|
83
|
+
- **sortField**: The field to sort by.
|
84
|
+
- **sortOrder**: The order of sorting (ascending or descending).
|
85
|
+
- **fields**: Comma-separated list of fields to include in the result.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pagination.service.d.ts","sourceRoot":"","sources":["../src/pagination.service.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,SAAS,EACT,YAAY,EACZ,eAAe,EACf,gBAAgB,EACjB,MAAM,0BAA0B,CAAC;AAElC,qBACa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;IAEvD,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,SAAS,EACnC,KAAK,EAAE,CAAC,EACR,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GAC5B,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"pagination.service.d.ts","sourceRoot":"","sources":["../src/pagination.service.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,SAAS,EACT,YAAY,EACZ,eAAe,EACf,gBAAgB,EACjB,MAAM,0BAA0B,CAAC;AAElC,qBACa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;IAEvD,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,SAAS,EACnC,KAAK,EAAE,CAAC,EACR,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GAC5B,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAwG9B,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE;IAavD,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO;IAI5D,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO;CAK7D"}
|
@@ -61,6 +61,7 @@ let PaginationService = PaginationService_1 = class PaginationService {
|
|
61
61
|
const query = {
|
62
62
|
select: selectCondition,
|
63
63
|
where: (customQuery === null || customQuery === void 0 ? void 0 : customQuery.where) || {},
|
64
|
+
include: (customQuery === null || customQuery === void 0 ? void 0 : customQuery.include) || {},
|
64
65
|
orderBy: sortOrderCondition,
|
65
66
|
take: pageSize,
|
66
67
|
skip,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pagination.service.js","sourceRoot":"","sources":["../src/pagination.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAyE;AACzE,2EAG0C;AAC1C,+DAA8D;AASvD,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAAvB;QACY,WAAM,GAAG,IAAI,eAAM,CAAC,mBAAiB,CAAC,IAAI,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"pagination.service.js","sourceRoot":"","sources":["../src/pagination.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAyE;AACzE,2EAG0C;AAC1C,+DAA8D;AASvD,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAAvB;QACY,WAAM,GAAG,IAAI,eAAM,CAAC,mBAAiB,CAAC,IAAI,CAAC,CAAC;IAoI/D,CAAC;IAlIC,KAAK,CAAC,QAAQ,CACZ,KAAQ,EACR,gBAAkC,EAClC,WAA6B;QAE7B,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,CAAC,gBAAgB,CAAC,IAAI,IAAI,mCAAY,CAAC,CAAC;YAC3D,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CAAC,QAAQ,IAAI,wCAAiB,CAAC,CAAC;YACxE,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,IAAI,IAAI,CAAC;YAC/C,MAAM,SAAS,GAAG,gBAAgB,CAAC,SAAS,IAAI,IAAI,CAAC;YACrD,MAAM,SAAS,GAAG,gBAAgB,CAAC,SAAS,IAAI,qCAAkB,CAAC,GAAG,CAAC;YACvE,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM;gBACpC,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;gBACpC,CA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