diff --git a/src/services/brand.service.ts b/src/services/brand.service.ts index 20b935d..9be94bf 100644 --- a/src/services/brand.service.ts +++ b/src/services/brand.service.ts @@ -124,12 +124,40 @@ async function getByIdBrand(brandId: string): Promise { return brand; } +//TODO get models of the brand + +/** + * Deletes a brand from the database. + * + * @param {string} brandId - The ID of the brand to delete. + * @return {Promise} - A promise that resolves to true if the brand was deleted successfully, or false otherwise. + */ +async function deleteBrand(brandId: string): Promise { + if (!brandId) { + logger.error("Brand ID is missing"); + return false; + } + if (brandId.length !== 36) { + logger.error("Invalid brand ID"); + return false; + } + //TODO verify if as models linked + const deletedBrand = await MysqlService.Brand.delete(DbHandler, brandId); + if (!deletedBrand) { + logger.error(`Failed to delete brand (${brandId})`); + return false; + } + logger.info(`Brand deleted successfully (${brandId})`); + return true; +} + const BrandService = { create: createBrand, update: updateBrand, getAll: getAllBrand, getBySlug: getBySlugBrand, getById: getByIdBrand, + delete: deleteBrand, } export default BrandService; \ No newline at end of file