feat(services): update category service functions
Update category service functions with added getBySlug function and refactor getAllCategory to getAll. Exception handling has been improved, returning null on error. Issue: #11 Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
parent
3d3bc8580a
commit
11be3a40c3
@ -30,18 +30,31 @@ async function createCategory(data: IDbCategory): Promise<unknown> {
|
||||
}
|
||||
}
|
||||
|
||||
//FEAT Get all categories
|
||||
async function getAllCategory() {
|
||||
/**
|
||||
* Retrieves all categories from the database.
|
||||
*
|
||||
* @returns {Promise<Array<IDbCategory>> | null} Promise that resolves to an array of IDbCategory objects or null if an error occurred.
|
||||
*/
|
||||
async function getAll(): Promise<Promise<Array<IDbCategory>> | null> {
|
||||
try {
|
||||
logger.info("Getting all categories...");
|
||||
return await MysqlService.Category.getAll(DbHandler);
|
||||
} catch (error) {
|
||||
logger.error(`Error getting all categories: ${error}`);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//FEAT Get a category (slug)
|
||||
async function getBySlug(slug: string) {
|
||||
try {
|
||||
logger.info(`Getting category by slug... (${slug})`);
|
||||
return await MysqlService.Category.getBySlug(DbHandler, slug);
|
||||
} catch (error) {
|
||||
logger.error(`Error getting category by slug: ${error}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//FEAT Get a category (id)
|
||||
|
||||
@ -51,7 +64,8 @@ async function getAllCategory() {
|
||||
|
||||
const CategoryService = {
|
||||
create: createCategory,
|
||||
getAll: getAllCategory
|
||||
getAll,
|
||||
getBySlug
|
||||
}
|
||||
|
||||
export default CategoryService;
|
Loading…
x
Reference in New Issue
Block a user