import { Injectable } from '@nestjs/common'; import { CreateCategoryDto } from './dto/create-category.dto'; import { UpdateCategoryDto } from './dto/update-category.dto'; import { CategoryDataService } from './category-data.service'; import { Category } from './entities/category.entity'; @Injectable() export class CategoriesService { public constructor(private categoryDataService: CategoryDataService) { } public async findAll(): Promise { return await this.categoryDataService.getAll(); } public async findById(id: string): Promise { const category = await this.categoryDataService.getById(id); if (!category) { throw new Error('No category found'); } return category; } public async create(category: CreateCategoryDto): Promise { return await this.categoryDataService.create(category.name); } public async update(category: UpdateCategoryDto): Promise { return await this.categoryDataService.update(category); } public async remove(id: string): Promise { await this.categoryDataService.delete(id); } }