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:
parent
6c626e0b18
commit
5c0d266002
@ -124,12 +124,40 @@ async function getByIdBrand(brandId: string): Promise<IDbBrand | false> {
|
|||||||
return brand;
|
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 = {
|
const BrandService = {
|
||||||
create: createBrand,
|
create: createBrand,
|
||||||
update: updateBrand,
|
update: updateBrand,
|
||||||
getAll: getAllBrand,
|
getAll: getAllBrand,
|
||||||
getBySlug: getBySlugBrand,
|
getBySlug: getBySlugBrand,
|
||||||
getById: getByIdBrand,
|
getById: getByIdBrand,
|
||||||
|
delete: deleteBrand,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BrandService;
|
export default BrandService;
|
Loading…
x
Reference in New Issue
Block a user