Skip to content
This repository was archived by the owner on Jul 20, 2026. It is now read-only.

Commit 01a070f

Browse files
committed
Fixed the ?showHidden in getAllProducts
1 parent 5c4fa07 commit 01a070f

4 files changed

Lines changed: 54 additions & 5 deletions

File tree

backend/src/controllers/product.controller.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ export class ProductController extends BaseController {
1414

1515
getAll = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
1616
try {
17-
const products = await this.productFcd.getAllFullProducts();
17+
const showHidden = req.query.showHidden !== 'false';
18+
19+
const products = await this.productFcd.getAllFullProducts(showHidden);
1820

1921
this.sendResponse(res, HttpStatus.OK, 'Products retrieved successfully', products);
2022
} catch (error) {

backend/src/routes/product.routes.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Router } from 'express';
2-
import { body, param } from 'express-validator';
2+
import { body, param, query } from 'express-validator';
33

44
import { adminMiddleware, authMiddleware } from '../middlewares/auth.middleware';
55
import { validateRequest } from '../middlewares/validation.middleware';
@@ -9,6 +9,7 @@ import { productController } from '../container';
99
const router = Router();
1010

1111
const idValidation = [param('id').isInt().withMessage('Invalid ID')];
12+
const showHiddenValidation = [query('showHidden').isBoolean().withMessage('showHidden should be a boolean')];
1213

1314
//.custom((value) => value === null || typeof value === 'number').withMessage('Supplier ID must be a number or null')
1415
const productValidation = {
@@ -29,7 +30,7 @@ const productValidation = {
2930
};
3031

3132
// Public routes
32-
router.get('/', productController.getAll);
33+
router.get('/', showHiddenValidation, validateRequest, productController.getAll);
3334
router.get('/:id', idValidation, validateRequest, productController.getById);
3435
router.get('/:id/detail', idValidation, validateRequest, productController.getFullProduct);
3536

backend/src/services/product.facade.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export class ProductFacade {
3737
return fullProduct;
3838
}
3939

40-
async getAllFullProducts(): Promise<ProductResponse[]> {
41-
const products = await this.productSvc.getAll();
40+
async getAllFullProducts(showHidden = true): Promise<ProductResponse[]> {
41+
const products = await this.productSvc.getAll(showHidden);
4242
return Promise.all(products.map(prod => this.getFullProduct(prod.id)));
4343
}
4444
}

docs/api.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ req: {
1212
id: Number,
1313
...
1414
},
15+
query: {
16+
...
17+
},
1518
body: {
1619
...
1720
}
@@ -35,6 +38,7 @@ res: {
3538
```json
3639
req: {
3740
params: {},
41+
query: {},
3842
body: {
3943
firstName: String,
4044
lastName: String,
@@ -73,6 +77,7 @@ res: {
7377
```json
7478
req: {
7579
params: {},
80+
query: {},
7681
body: {
7782
email: String,
7883
password: String
@@ -113,6 +118,7 @@ req: {
113118
role: String
114119
},
115120
params: {},
121+
query: {},
116122
body: {}
117123
}
118124
```
@@ -149,6 +155,7 @@ req: {
149155
params: {
150156
id: Number
151157
},
158+
query: {},
152159
body: {
153160
firstName?: String,
154161
lastName?: String,
@@ -192,6 +199,7 @@ req: {
192199
params: {
193200
id: Number
194201
},
202+
query: {},
195203
body: {}
196204
}
197205
```
@@ -216,6 +224,7 @@ req: {
216224
role: String
217225
},
218226
params: {},
227+
query: {},
219228
body: {}
220229
}
221230
```
@@ -248,6 +257,7 @@ req: {
248257
params: {
249258
id: Number
250259
},
260+
query: {},
251261
body: {}
252262
}
253263
```
@@ -278,6 +288,7 @@ res: {
278288
```json
279289
req: {
280290
params: {},
291+
query: {},
281292
body: {}
282293
}
283294
```
@@ -304,6 +315,7 @@ req: {
304315
params: {
305316
id: Number
306317
},
318+
query: {},
307319
body: {}
308320
}
309321
```
@@ -326,6 +338,7 @@ res: {
326338
```json
327339
req: {
328340
params: {},
341+
query: {},
329342
body: {
330343
name: String
331344
}
@@ -352,6 +365,7 @@ req: {
352365
params: {
353366
id: Number
354367
},
368+
query: {},
355369
body: {
356370
name?: String
357371
}
@@ -378,6 +392,7 @@ req: {
378392
params: {
379393
id: Number
380394
},
395+
query: {},
381396
body: {}
382397
}
383398
```
@@ -399,6 +414,7 @@ res: {
399414
```json
400415
req: {
401416
params: {},
417+
query: {},
402418
body: {}
403419
}
404420
```
@@ -430,6 +446,7 @@ req: {
430446
params: {
431447
id: Number
432448
},
449+
query: {},
433450
body: {}
434451
}
435452
```
@@ -457,6 +474,7 @@ res: {
457474
```json
458475
req: {
459476
params: {},
477+
query: {},
460478
body: {
461479
name: String,
462480
contactInfo: {
@@ -492,6 +510,7 @@ req: {
492510
params: {
493511
id: Number
494512
},
513+
query: {},
495514
body: {
496515
name?: String,
497516
contactInfo?: {
@@ -527,6 +546,7 @@ req: {
527546
params: {
528547
id: Number
529548
},
549+
query: {},
530550
body: {}
531551
}
532552
```
@@ -548,6 +568,7 @@ res: {
548568
```json
549569
req: {
550570
params: {},
571+
query: {},
551572
body: {}
552573
}
553574
```
@@ -578,6 +599,7 @@ req: {
578599
params: {
579600
id: Number
580601
},
602+
query: {},
581603
body: {}
582604
}
583605
```
@@ -608,6 +630,7 @@ req: {
608630
params: {
609631
id: Number
610632
},
633+
query: {},
611634
body: {}
612635
}
613636
```
@@ -646,6 +669,7 @@ res: {
646669
```json
647670
req: {
648671
params: {},
672+
query: {},
649673
body: {
650674
productId: Number,
651675
categoryId: Number,
@@ -680,6 +704,7 @@ req: {
680704
params: {
681705
id: Number
682706
},
707+
query: {},
683708
body: {
684709
productId?: Number,
685710
categoryId?: Number,
@@ -714,6 +739,7 @@ req: {
714739
params: {
715740
id: Number
716741
},
742+
query: {},
717743
body: {}
718744
}
719745
```
@@ -735,6 +761,7 @@ req: {
735761
params: {
736762
id: Number
737763
},
764+
query: {},
738765
body: {
739766
productId: Number,
740767
priceDelta: Number,
@@ -767,6 +794,7 @@ req: {
767794
params: {
768795
id: Number
769796
},
797+
query: {},
770798
body: {
771799
productId: Number,
772800
priceDelta?: Number,
@@ -799,6 +827,7 @@ req: {
799827
params: {
800828
id: Number
801829
},
830+
query: {},
802831
body: {
803832
productId: Number
804833
}
@@ -822,6 +851,9 @@ res: {
822851
```json
823852
req: {
824853
params: {},
854+
query: {
855+
showHidden: Boolean
856+
},
825857
body: {}
826858
}
827859
```
@@ -852,6 +884,7 @@ req: {
852884
params: {
853885
id: Number
854886
},
887+
query: {},
855888
body: {}
856889
}
857890
```
@@ -880,6 +913,7 @@ req: {
880913
params: {
881914
id: Number
882915
},
916+
query: {},
883917
body: {}
884918
}
885919
```
@@ -940,6 +974,7 @@ res: {
940974
```json
941975
req: {
942976
params: {},
977+
query: {},
943978
body: {
944979
name: String,
945980
description?: String,
@@ -975,6 +1010,7 @@ req: {
9751010
params: {
9761011
id: Number
9771012
},
1013+
query: {},
9781014
body: {
9791015
name?: String,
9801016
description?: String,
@@ -1011,6 +1047,7 @@ req: {
10111047
params: {
10121048
id: Number
10131049
},
1050+
query: {},
10141051
body: {}
10151052
}
10161053
```
@@ -1032,6 +1069,7 @@ res: {
10321069
```json
10331070
req: {
10341071
params: {},
1072+
query: {},
10351073
body: {}
10361074
}
10371075
```
@@ -1060,6 +1098,7 @@ res: {
10601098
```json
10611099
req: {
10621100
params: {},
1101+
query: {},
10631102
body: {}
10641103
}
10651104
```
@@ -1086,6 +1125,7 @@ res: {
10861125
```json
10871126
req: {
10881127
params: {},
1128+
query: {},
10891129
body: {
10901130
mode: String,
10911131
status?: String,
@@ -1118,6 +1158,7 @@ req: {
11181158
params: {
11191159
id: Number
11201160
},
1161+
query: {},
11211162
body: {
11221163
mode?: String,
11231164
status?: String,
@@ -1150,6 +1191,7 @@ res: {
11501191
```json
11511192
req: {
11521193
params: {},
1194+
query: {},
11531195
body: {}
11541196
}
11551197
```
@@ -1213,6 +1255,7 @@ req: {
12131255
params: {
12141256
id: Number
12151257
},
1258+
query: {},
12161259
body: {}
12171260
}
12181261
```
@@ -1272,6 +1315,7 @@ res: {
12721315
```json
12731316
req: {
12741317
params: {},
1318+
query: {},
12751319
body: {
12761320
accountId: Number,
12771321
amount: Number,
@@ -1360,6 +1404,7 @@ req: {
13601404
params: {
13611405
id: Number
13621406
},
1407+
query: {},
13631408
body: {
13641409
amount?: Number,
13651410
billingAddress?: {
@@ -1447,6 +1492,7 @@ req: {
14471492
params: {
14481493
id: Number
14491494
},
1495+
query: {},
14501496
body: {}
14511497
}
14521498
```

0 commit comments

Comments
 (0)