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 <yidhra@tuta.io>
This commit is contained in:
Mathis H (Avnyr) 2024-04-29 11:29:29 +02:00
parent 915b205b6e
commit 041e77efcd
Signed by: Mathis
GPG Key ID: DD9E0666A747D126
2 changed files with 11 additions and 7 deletions

View File

@ -92,12 +92,13 @@ async function getBySlugBrand(req: Request, res: Response): Promise<Response> {
}
/**
* Retrieves all brands and sends the response.
* Retrieves all brands.
*
* @param {Request} _req - The request object.
* @param {Response} res - The response object.
* @returns {Promise<Response>} - A Promise that resolves with the response object.
* @returns {Promise<Response>} - A promise with the response object.
*/
async function getAllBrand(res: Response): Promise<Response> {
async function getAllBrand(_req: Request, res: Response): Promise<Response> {
const brands = await BrandService.getAll();
if (!brands) {
logger.error("Failed to retrieve brands");

View File

@ -97,24 +97,27 @@ async function deleteCategory(req: Request, res: Response): Promise<Response> {
/**
* Retrieves all categories.
*
* @param _req
* @param {Response} res - The response object.
* @return {Promise<Response>} - A promise that resolves to the response object.
*/
async function getAllCategory(res: Response): Promise<Response> {
async function getAllCategory(_req: Request, res: Response): Promise<Response> {
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
});
}