Compare commits

...

2 Commits

Author SHA1 Message Date
f3cd6c5985
fix(services): correct MysqlService method calls in category.service.ts
Several method calls in category.service.ts were incorrectly using IDbCategory instead of Category in MysqlService. This commit fixes the naming to correctly use Category in all method calls to ensure correct function execution.

Issue: #11
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 14:00:07 +02:00
325c6ec6a0
feat(services): update methods in category service
Refactor the category service by:
- Calling methods from MysqlService.IDbCategory instead of MysqlService.Category.
- Adding new methods: getById and deleteCategory with typed return and clear comments.
These changes enhances code flexibility and readability.

Issue: #11
Signed-off-by: Mathis <yidhra@tuta.io>
2024-04-25 13:55:55 +02:00

View File

@ -45,8 +45,14 @@ async function getAll(): Promise<Promise<Array<IDbCategory>> | null> {
}
}
//FEAT Get a category (slug)
async function getBySlug(slug: string) {
/**
* Gets a category by its slug
*
* @param {string} slug - The slug of the category
* @return {Promise<IDbCategory|null>} - A promise that resolves to the category object or null if not found
*/
async function getBySlug(slug: string): Promise<IDbCategory | null> {
try {
logger.info(`Getting category by slug... (${slug})`);
return await MysqlService.Category.getBySlug(DbHandler, slug);
@ -56,16 +62,47 @@ async function getBySlug(slug: string) {
}
}
//FEAT Get a category (id)
/**
* Retrieves a category from the database by its id.
*
* @param {string} id - The id of the category to retrieve.
* @returns {Promise<IDbCategory | null>} - A Promise that resolves with the retrieved category object or null if not found.
*/
async function getById(id: string):Promise<IDbCategory | null> {
try {
logger.info(`Getting category by id... (${id})`);
return await MysqlService.Category.getById(DbHandler, id);
} catch (error) {
logger.error(`Error getting category by id: ${error}`);
return null;
}
}
//FEAT Get all models in category (slug)
//FEAT Delete a category (id)
/**
* Deletes a category with the given ID from the database.
*
* @param {string} id - The ID of the category to delete.
* @return {Promise} - A Promise that resolves to the deleted category if successful, or null if an error occurs.
*/
async function deleteCategory(id:string): Promise<unknown> {
try {
logger.info(`Deleting category... (${id})`);
return await MysqlService.Category.delete(DbHandler, id);
} catch (error) {
logger.error(`Error deleting category: ${error}`);
return null;
}
}
const CategoryService = {
create: createCategory,
delete: deleteCategory,
getAll,
getBySlug
getBySlug,
getById
}
export default CategoryService;