feat(services): add deleteBrand function to brand.service.ts

The `brand.service.ts` file is updated to include a new function `deleteBrand`, which allows a brand to be deleted from the database by its ID. Appropriate error handling and activity logging have been incorporated to ensure smooth operation.

Issue: #13
Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
Mathis H (Avnyr) 2024-04-26 09:52:09 +02:00
parent 6c626e0b18
commit 5c0d266002
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -124,12 +124,40 @@ async function getByIdBrand(brandId: string): Promise<IDbBrand | false> {
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<boolean>} - A promise that resolves to true if the brand was deleted successfully, or false otherwise.
*/
async function deleteBrand(brandId: string): Promise<boolean> {
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;