diff --git a/src/services/brand.service.ts b/src/services/brand.service.ts index d5d2ada..b1ca699 100644 --- a/src/services/brand.service.ts +++ b/src/services/brand.service.ts @@ -78,10 +78,31 @@ async function getAllBrand(): Promise| false> { return brands; } +/** + * Retrieves a brand by its slug. + * + * @param {string} brandSlug - The slug of the brand. + * @returns {Promise} - A promise that resolves to the retrieved brand object or false if the brand is not found. + */ +async function getBySlugBrand(brandSlug: string): Promise { + if (!brandSlug) { + logger.error("Brand slug is missing"); + return false; + } + const brand = await MysqlService.Brand.getBySlug(DbHandler, brandSlug); + if (!brand) { + logger.error(`Brand not found (${brandSlug})`); + return false; + } + logger.info(`Retrieved brand by slug successfully (${brandSlug})`); + return brand; +} + const BrandService = { create: createBrand, update: updateBrand, getAll: getAllBrand, + getBySlug: getBySlugBrand, } export default BrandService; \ No newline at end of file