File: //home/arjun/projects/good-life-be/api/Category/service.js
import BadRequest from '../../helper/exception/badRequest.js';
import Category from '../../models/Category.js';
import SubCategory from '../../models/SubCategory.js';
export const categoryList = async () => {
const data = await Category.findAll({
attributes: ['id', 'name', 'color'],
order: [['updatedAt', 'ASC']],
});
if (!data) throw new BadRequest('No data found');
return data;
};
export const subcategoryList = async (categoryId) => {
if (!categoryId) throw new BadRequest('Category ID is required');
const data = await SubCategory.findAll({
where: { category_id: categoryId },
});
if (data.length === 0) {
throw new BadRequest('No subcategories found for this category');
}
return data;
};