added categories resource

This commit is contained in:
Joe Arndt 2026-02-08 16:43:22 -06:00
parent c90276982f
commit 50e2b6e2b7
8 changed files with 166 additions and 2 deletions

View file

@ -0,0 +1,35 @@
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);
}
}