Compare commits
No commits in common. "f3cd6c598583509077675e49b52da6ea61469528" and "11be3a40c382b61ef0b41c4ea6e1bfb930e12abe" have entirely different histories.
f3cd6c5985
...
11be3a40c3
@ -45,14 +45,8 @@ 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 {
|
try {
|
||||||
logger.info(`Getting category by slug... (${slug})`);
|
logger.info(`Getting category by slug... (${slug})`);
|
||||||
return await MysqlService.Category.getBySlug(DbHandler, slug);
|
return await MysqlService.Category.getBySlug(DbHandler, slug);
|
||||||
@ -62,47 +56,16 @@ async function getBySlug(slug: string): Promise<IDbCategory | null> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
//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 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 = {
|
const CategoryService = {
|
||||||
create: createCategory,
|
create: createCategory,
|
||||||
delete: deleteCategory,
|
|
||||||
getAll,
|
getAll,
|
||||||
getBySlug,
|
getBySlug
|
||||||
getById
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CategoryService;
|
export default CategoryService;
|
Loading…
x
Reference in New Issue
Block a user