From 041e77efcd4adee1bd8c6c365339eb2c72d14fe2 Mon Sep 17 00:00:00 2001 From: Mathis Date: Mon, 29 Apr 2024 11:29:29 +0200 Subject: [PATCH] feat(controllers): include request param to getAll functions Changes include the inclusion of the request parameter (`_req`) in the `getAllBrand` and `getAllCategory` functions and some code format adjustment in `category.controller.ts`. This addition allows more flexibility in handling the request if needed in the future. The `total` field has also been added to the category output to conveniently provide category count. Signed-off-by: Mathis --- src/controllers/brand.controller.ts | 7 ++++--- src/controllers/category.controller.ts | 11 +++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/controllers/brand.controller.ts b/src/controllers/brand.controller.ts index d716367..9ae4c74 100644 --- a/src/controllers/brand.controller.ts +++ b/src/controllers/brand.controller.ts @@ -92,12 +92,13 @@ async function getBySlugBrand(req: Request, res: Response): Promise { } /** - * Retrieves all brands and sends the response. + * Retrieves all brands. * + * @param {Request} _req - The request object. * @param {Response} res - The response object. - * @returns {Promise} - A Promise that resolves with the response object. + * @returns {Promise} - A promise with the response object. */ -async function getAllBrand(res: Response): Promise { +async function getAllBrand(_req: Request, res: Response): Promise { const brands = await BrandService.getAll(); if (!brands) { logger.error("Failed to retrieve brands"); diff --git a/src/controllers/category.controller.ts b/src/controllers/category.controller.ts index fe603bd..0c3d93c 100644 --- a/src/controllers/category.controller.ts +++ b/src/controllers/category.controller.ts @@ -97,24 +97,27 @@ async function deleteCategory(req: Request, res: Response): Promise { /** * Retrieves all categories. * + * @param _req * @param {Response} res - The response object. * @return {Promise} - A promise that resolves to the response object. */ -async function getAllCategory(res: Response): Promise { +async function getAllCategory(_req: Request, res: Response): Promise { const categories = await CategoryService.getAll(); if (!categories) { logger.error("Failed to get categories"); return res.status(500).json({ error: "Failed to get categories" }); } logger.info("Categories retrieved successfully"); - //ToTest categories output type - return res.status(200).json({ + return res + .status(200) + .json({ iat: Date.now(), categories: categories.map((category: IDbCategory) => ({ id: category.id, display_name: category.display_name, slug_name: category.slug_name - })) + })), + total: categories.length }); }