feat(services): update category.service with improved UUID usage and new function
The commit updates the 'category.service.ts' file by refactoring the UUID usage. Previously, the UUID feature was imported as a whole, but now only the v4 function is imported for efficiency. It introduces a new function 'getAllCategory' to fetch all categories. This, combined with better error handling and logging, leads to improved service reliability. Issue: #11 Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
parent
38b6b05190
commit
3d3bc8580a
@ -1,6 +1,6 @@
|
||||
//FEAT Create new category
|
||||
import type IDbCategory from "@interfaces/database/IDbCategory";
|
||||
import * as uuid from 'uuid'
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import {Logger} from "tslog";
|
||||
import MysqlService from "@services/mysql.service";
|
||||
|
||||
@ -20,17 +20,26 @@ async function createCategory(data: IDbCategory): Promise<unknown> {
|
||||
logger.info(`Creating a new category... (${data.display_name})`)
|
||||
try {
|
||||
return await MysqlService.Category.insert(DbHandler, {
|
||||
id: uuid.v4(undefined, undefined, undefined),
|
||||
id: uuidv4(),
|
||||
display_name: data.display_name,
|
||||
slug_name: data.slug_name
|
||||
})
|
||||
} catch (e) {
|
||||
logger.error(`Error creating category: ${e.message}`);
|
||||
} catch (error) {
|
||||
logger.error(`Error creating category: ${error}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//FEAT Get all categories
|
||||
async function getAllCategory() {
|
||||
try {
|
||||
logger.info("Getting all categories...");
|
||||
return await MysqlService.Category.getAll(DbHandler);
|
||||
} catch (error) {
|
||||
logger.error(`Error getting all categories: ${error}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//FEAT Get a category (slug)
|
||||
|
||||
@ -41,7 +50,8 @@ async function createCategory(data: IDbCategory): Promise<unknown> {
|
||||
//FEAT Delete a category (id)
|
||||
|
||||
const CategoryService = {
|
||||
create: createCategory
|
||||
create: createCategory,
|
||||
getAll: getAllCategory
|
||||
}
|
||||
|
||||
export default CategoryService;
|
Loading…
x
Reference in New Issue
Block a user