diff --git a/src/services/brand.service.ts b/src/services/brand.service.ts index b1ca699..20b935d 100644 --- a/src/services/brand.service.ts +++ b/src/services/brand.service.ts @@ -98,11 +98,38 @@ async function getBySlugBrand(brandSlug: string): Promise { return brand; } + +/** + * Retrieves a brand from the database based on the provided brand ID. + * + * @param {string} brandId - The ID of the brand to retrieve. + * + * @returns {Promise} A promise that resolves to the retrieved brand object, or false if the brand is not found or the ID is invalid. + */ +async function getByIdBrand(brandId: string): Promise { + if (!brandId) { + logger.error("Brand ID is missing"); + return false; + } + if (brandId.length !== 36) { + logger.error("Invalid brand ID"); + return false; + } + const brand = await MysqlService.Brand.getById(DbHandler, brandId); + if (!brand) { + logger.error(`Brand not found (${brandId})`); + return false; + } + logger.info(`Retrieved brand by ID successfully (${brandId})`); + return brand; +} + const BrandService = { create: createBrand, update: updateBrand, getAll: getAllBrand, getBySlug: getBySlugBrand, + getById: getByIdBrand, } export default BrandService; \ No newline at end of file