common-cents-api/src/categories/categories.service.ts
2026-02-08 16:43:22 -06:00

35 lines
1.1 KiB
TypeScript

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<Category[]> {
return await this.categoryDataService.getAll();
}
public async findById(id: string): Promise<Category> {
const category = await this.categoryDataService.getById(id);
if (!category) {
throw new Error('No category found');
}
return category;
}
public async create(category: CreateCategoryDto): Promise<Category> {
return await this.categoryDataService.create(category.name);
}
public async update(category: UpdateCategoryDto): Promise<Category> {
return await this.categoryDataService.update(category);
}
public async remove(id: string): Promise<void> {
await this.categoryDataService.delete(id);
}
}