File tree 4 files changed +34
-30
lines changed
4 files changed +34
-30
lines changed Original file line number Diff line number Diff line change @@ -75,10 +75,6 @@ export class jobController {
75
75
entityExternalId
76
76
) ;
77
77
78
- if ( entityObj === null || parseInt ( limit ) <= 0 ) {
79
- return returnValues ;
80
- }
81
-
82
78
let condition = { } ;
83
79
if ( Boolean ( dateFrom ) && Boolean ( dateTo ) ) {
84
80
condition = {
@@ -92,23 +88,22 @@ export class jobController {
92
88
93
89
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
94
90
//@ts -ignore
95
- const countData = await entityObj . getJobs ( condition ) ;
96
- let cont = 0 ;
97
- countData . forEach ( ( job ) => {
98
- if ( job ) {
99
- cont ++ ;
100
- }
101
- } ) ;
91
+ const countData : Job [ ] = await entityObj . getJobs ( condition ) ;
92
+ const cont = countData . length ;
102
93
103
- const pages = Math . ceil ( cont / limit ) ;
104
- const offset = limit * ( page - 1 ) ;
105
- condition = {
106
- ...condition ,
107
- ...{
108
- offset : offset ,
109
- limit : limit ,
110
- } ,
111
- } ;
94
+ let pages = 1 ;
95
+
96
+ if ( limit > 0 && page >= 0 ) {
97
+ pages = Math . ceil ( cont / limit ) ;
98
+ const offset = limit * page ;
99
+ condition = {
100
+ ...condition ,
101
+ ...{
102
+ offset : offset ,
103
+ limit : limit ,
104
+ } ,
105
+ } ;
106
+ }
112
107
113
108
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
114
109
//@ts -ignore - getJobs(): metodo autogenerato dall'ORM Sequelize dopo l'associazione
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " crawler-handler" ,
3
- "version" : " 3.1.0 " ,
3
+ "version" : " 3.1.1 " ,
4
4
"description" : " Handler per il validatore di comuni e scuole" ,
5
5
"main" : " index.js" ,
6
6
"type" : " module" ,
Original file line number Diff line number Diff line change @@ -414,6 +414,18 @@ router.post(
414
414
* type: string
415
415
* description: La tipologia di Entity
416
416
* example: "municipality"
417
+ * - name: limit
418
+ * in: query
419
+ * schema:
420
+ * type: number
421
+ * description: Paginazione - quantità di risultati restituiti per pagina
422
+ * example: 10
423
+ * - name: page
424
+ * in: query
425
+ * schema:
426
+ * type: number
427
+ * description: Paginazione - pagina da visualizzare
428
+ * example: 5
417
429
* responses:
418
430
* "200":
419
431
* description: OK
@@ -613,11 +625,8 @@ router.get(
613
625
const dateFrom = req . query . dateFrom ;
614
626
const dateTo = req . query . dateTo ;
615
627
616
- const page =
617
- req . query . page === "0" || req . query . page === undefined
618
- ? "1"
619
- : req . query . page ;
620
- const limit = req . query . limit ?? "0" ;
628
+ const page = req . query . page ?? "0" ;
629
+ const limit = req . query . limit ?? "-1" ;
621
630
622
631
const result = await new jobController ( dbWS ) . list (
623
632
externalEntityId ,
@@ -944,9 +953,9 @@ router.post(
944
953
try {
945
954
await jwtVerify ( process . env . JWT_SECRET , await getToken ( req ) ) ;
946
955
947
- const page = req . query . page ;
948
-
956
+ const page = req . query . page ?? "0" ;
949
957
const limit = req . query . limit ?? "-1" ;
958
+
950
959
const countOnly = req . query . countOnly
951
960
? req . query . countOnly == "true"
952
961
: false ;
You can’t perform that action at this time.
0 commit comments