feat(services): add getBySlugBrand function in brand.service
Adds a new function `getBySlugBrand` in `brand.service.ts`. This function retrieves a brand by its slug, providing a more specific search option. It implements error logging for missing slug or brand not found scenarios, and successful retrieval of the brand. Issue: #13 Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
parent
33d44ee4b6
commit
aecaf83d85
@ -78,10 +78,31 @@ async function getAllBrand(): Promise<Array<IDbBrand>| false> {
|
|||||||
return brands;
|
return brands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a brand by its slug.
|
||||||
|
*
|
||||||
|
* @param {string} brandSlug - The slug of the brand.
|
||||||
|
* @returns {Promise<IDbBrand|false>} - A promise that resolves to the retrieved brand object or false if the brand is not found.
|
||||||
|
*/
|
||||||
|
async function getBySlugBrand(brandSlug: string): Promise<IDbBrand | false> {
|
||||||
|
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 = {
|
const BrandService = {
|
||||||
create: createBrand,
|
create: createBrand,
|
||||||
update: updateBrand,
|
update: updateBrand,
|
||||||
getAll: getAllBrand,
|
getAll: getAllBrand,
|
||||||
|
getBySlug: getBySlugBrand,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BrandService;
|
export default BrandService;
|
Loading…
x
Reference in New Issue
Block a user