@tc-libs/pagination 3.5.0 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +68 -6
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,11 +1,73 @@
1
- # pagination
1
+ # @tc-libs/pagination
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ Toolkit per query pagination/filter/order/search su endpoint NestJS.
4
4
 
5
- ## Building
5
+ Il package contiene:
6
6
 
7
- Run `nx build pagination` to build the library.
7
+ - `PaginationModule` e `PaginationService`
8
+ - decorator parametrici per query string
9
+ - pipe per paging, order, search e filtri
10
+ - costanti ed enum condivisi
8
11
 
9
- ## Running unit tests
12
+ ## Servizio
10
13
 
11
- Run `nx test pagination` to execute the unit tests via [Jest](https://jestjs.io).
14
+ `PaginationService` espone la logica base:
15
+
16
+ - `page()`, `perPage()`, `offset()`, `totalPages()`
17
+ - `order()`
18
+ - `search()`
19
+ - `filterEqual()`, `filterNotEqual()`, `filterContain()`, `filterIn()`, `filterDate()`
20
+
21
+ Esempio:
22
+
23
+ ```ts
24
+ const page = this.paginationService.page(query.page);
25
+ const perPage = this.paginationService.perPage(false, query.perPage);
26
+ const offset = this.paginationService.offset(page, perPage);
27
+ ```
28
+
29
+ ## Decorator principali
30
+
31
+ Il decorator piu utile e `PaginationQuery(...)`:
32
+
33
+ ```ts
34
+ @Get()
35
+ list(
36
+ @PaginationQuery(
37
+ 20,
38
+ 'createdAt',
39
+ ENUM_PAGINATION_ORDER_DIRECTION_TYPE.ASC,
40
+ ['name', 'email'],
41
+ ['createdAt', 'name'],
42
+ )
43
+ query: PaginationListDto,
44
+ ) {}
45
+ ```
46
+
47
+ Il decorator applica automaticamente:
48
+
49
+ - search pipe
50
+ - paging pipe
51
+ - order pipe
52
+ - select pipe
53
+
54
+ Sono disponibili anche decorator piu specifici come:
55
+
56
+ - `PaginationQueryFilterEqual`
57
+ - `PaginationQueryFilterContain`
58
+ - `PaginationQueryFilterDate`
59
+ - `PaginationQueryFilterInEnum`
60
+ - `PaginationQueryFilterEqualObjectId`
61
+
62
+ ## Come si integra con `request` e `response`
63
+
64
+ - i pipe salvano metadati di pagination in `request.__pagination`
65
+ - `@tc-libs/response` li usa per costruire `_metadata.pagination` e i cursori
66
+ - `@tc-libs/service` usa `PaginationService` per il metodo `paginate()`
67
+
68
+ ## Sviluppo
69
+
70
+ ```bash
71
+ nx build pagination
72
+ nx test pagination
73
+ ```
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@tc-libs/pagination",
3
- "version": "3.5.0",
3
+ "version": "3.6.1",
4
4
  "dependencies": {
5
- "@tc-libs/helper": "3.5.0",
6
- "@tc-libs/errors": "3.5.0",
5
+ "@tc-libs/helper": "3.6.1",
6
+ "@tc-libs/errors": "3.6.1",
7
7
  "@nestjs/common": "^11.0.12",
8
8
  "@nestjs/swagger": "^11.1.0",
9
9
  "express": "5.0.1",