feat(services): add getAllBrand function in BrandService
The BrandService in the services module now includes a new functionality - the getAllBrand function. This function retrieves all brands from the database. Loggers have been added to check successful retrieval and error handling. Issue: #13 Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
parent
90cd80e540
commit
33d44ee4b6
@ -64,9 +64,24 @@ async function updateBrand(data: IDbBrand): Promise<boolean> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all brands from the database.
|
||||||
|
* @returns {Promise<Array<IDbBrand>|false>} - An array of IDbBrand objects if successful, false otherwise.
|
||||||
|
*/
|
||||||
|
async function getAllBrand(): Promise<Array<IDbBrand>| false> {
|
||||||
|
const brands = await MysqlService.Brand.getAll(DbHandler);
|
||||||
|
if (!brands) {
|
||||||
|
logger.error("Failed to retrieve brands");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
logger.info(`Retrieved all brands successfully (${brands.length})`);
|
||||||
|
return brands;
|
||||||
|
}
|
||||||
|
|
||||||
const BrandService = {
|
const BrandService = {
|
||||||
create: createBrand,
|
create: createBrand,
|
||||||
update: updateBrand
|
update: updateBrand,
|
||||||
|
getAll: getAllBrand,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BrandService;
|
export default BrandService;
|
Loading…
x
Reference in New Issue
Block a user