Compare commits
3 Commits
90cd80e540
...
6c626e0b18
Author | SHA1 | Date | |
---|---|---|---|
6c626e0b18 | |||
aecaf83d85 | |||
33d44ee4b6 |
@ -64,9 +64,72 @@ 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
|
||||
update: updateBrand,
|
||||
getAll: getAllBrand,
|
||||
getBySlug: getBySlugBrand,
|
||||
getById: getByIdBrand,
|
||||
}
|
||||
|
||||
export default BrandService;
|
Loading…
x
Reference in New Issue
Block a user