From 33d44ee4b617245ddc86c567ee1c87947b6d8baf Mon Sep 17 00:00:00 2001 From: Mathis Date: Fri, 26 Apr 2024 09:35:55 +0200 Subject: [PATCH] feat(services): add getAllBrand function in BrandService The BrandService in the services module now includes a new functionality - the getAllBrand function. This function retrieves all brands from the database. Loggers have been added to check successful retrieval and error handling. Issue: #13 Signed-off-by: Mathis --- src/services/brand.service.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/services/brand.service.ts b/src/services/brand.service.ts index ffd1f77..d5d2ada 100644 --- a/src/services/brand.service.ts +++ b/src/services/brand.service.ts @@ -64,9 +64,24 @@ async function updateBrand(data: IDbBrand): Promise { return false; } +/** + * Retrieves all brands from the database. + * @returns {Promise|false>} - An array of IDbBrand objects if successful, false otherwise. + */ +async function getAllBrand(): Promise| false> { + const brands = await MysqlService.Brand.getAll(DbHandler); + if (!brands) { + logger.error("Failed to retrieve brands"); + return false; + } + logger.info(`Retrieved all brands successfully (${brands.length})`); + return brands; +} + const BrandService = { create: createBrand, - update: updateBrand + update: updateBrand, + getAll: getAllBrand, } export default BrandService; \ No newline at end of file