Compare commits
2 Commits
11be3a40c3
...
f3cd6c5985
Author | SHA1 | Date | |
---|---|---|---|
f3cd6c5985 | |||
325c6ec6a0 |
@ -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;
|
Loading…
x
Reference in New Issue
Block a user