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:
parent
915b205b6e
commit
041e77efcd
@ -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.
|
* @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();
|
const brands = await BrandService.getAll();
|
||||||
if (!brands) {
|
if (!brands) {
|
||||||
logger.error("Failed to retrieve brands");
|
logger.error("Failed to retrieve brands");
|
||||||
|
@ -97,24 +97,27 @@ async function deleteCategory(req: Request, res: Response): Promise<Response> {
|
|||||||
/**
|
/**
|
||||||
* Retrieves all categories.
|
* Retrieves all categories.
|
||||||
*
|
*
|
||||||
|
* @param _req
|
||||||
* @param {Response} res - The response object.
|
* @param {Response} res - The response object.
|
||||||
* @return {Promise<Response>} - A promise that resolves to 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();
|
const categories = await CategoryService.getAll();
|
||||||
if (!categories) {
|
if (!categories) {
|
||||||
logger.error("Failed to get categories");
|
logger.error("Failed to get categories");
|
||||||
return res.status(500).json({ error: "Failed to get categories" });
|
return res.status(500).json({ error: "Failed to get categories" });
|
||||||
}
|
}
|
||||||
logger.info("Categories retrieved successfully");
|
logger.info("Categories retrieved successfully");
|
||||||
//ToTest categories output type
|
return res
|
||||||
return res.status(200).json({
|
.status(200)
|
||||||
|
.json({
|
||||||
iat: Date.now(),
|
iat: Date.now(),
|
||||||
categories: categories.map((category: IDbCategory) => ({
|
categories: categories.map((category: IDbCategory) => ({
|
||||||
id: category.id,
|
id: category.id,
|
||||||
display_name: category.display_name,
|
display_name: category.display_name,
|
||||||
slug_name: category.slug_name
|
slug_name: category.slug_name
|
||||||
}))
|
})),
|
||||||
|
total: categories.length
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user