Compare commits

..

No commits in common. "6c626e0b18a511298eee818ba7e2e3cf1fe92933" and "90cd80e54069b6ca9349701a99bf83d53832cd09" have entirely different histories.

View File

@ -64,72 +64,9 @@ async function updateBrand(data: IDbBrand): Promise<boolean> {
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;
}
/**
* 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;
}
/**
* Retrieves a brand from the database based on the provided brand ID.
*
* @param {string} brandId - The ID of the brand to retrieve.
*
* @returns {Promise<IDbBrand | false>} A promise that resolves to the retrieved brand object, or false if the brand is not found or the ID is invalid.
*/
async function getByIdBrand(brandId: string): Promise<IDbBrand | false> {
if (!brandId) {
logger.error("Brand ID is missing");
return false;
}
if (brandId.length !== 36) {
logger.error("Invalid brand ID");
return false;
}
const brand = await MysqlService.Brand.getById(DbHandler, brandId);
if (!brand) {
logger.error(`Brand not found (${brandId})`);
return false;
}
logger.info(`Retrieved brand by ID successfully (${brandId})`);
return brand;
}
const BrandService = {
create: createBrand,
update: updateBrand,
getAll: getAllBrand,
getBySlug: getBySlugBrand,
getById: getByIdBrand,
update: updateBrand
}
export default BrandService;